Skip to content

[Swift 6]: Add ranges concept #823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

meatball133
Copy link
Member

@meatball133 meatball133 commented Jan 4, 2025

TODO:

Add hints file

@meatball133 meatball133 added this to the Swift 6.0 milestone Jan 4, 2025
Copy link
Contributor

github-actions bot commented Jan 4, 2025

Hello 👋 Thanks for your PR.

This repo does not currently have dedicated maintainers. Our cross-track maintainers team will attempt to review and merge your PR, but it will likely take longer for your PR to be reviewed.

If you enjoy contributing to Exercism and have a track-record of doing so successfully, you might like to become an Exercism maintainer for this track.

Please feel free to ask any questions, or chat to us about anything to do with this PR or the reviewing process on the Exercism forum.

(cc @exercism/cross-track-maintainers)

@meatball133 meatball133 mentioned this pull request Mar 30, 2025
49 tasks
@meatball133 meatball133 marked this pull request as ready for review April 19, 2025 20:25

| Method                  | Description                                                             | Example                         |
| ----------------------- | ----------------------------------------------------------------------- | ------------------------------------- |
| `count`       | Returns the size of the range                                         | `(1...5).count // returns 5` |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the columns line up?

@@ -0,0 +1,7 @@
{
"blurb": "Optionals can be used to represent the possible absence of a value.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look like a ranges blurb.

| `count`        | Returns the size of the range                                         | `(1...5).count // returns 5` |
| [`contains`][contains] | Returns `true` if the range includes the given value, otherwise `false` | `(1...5).contains(3) // Returns true` |

## Endless & beginless ranges
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Endless & beginless ranges
## Endless and beginless ranges


```swift
let range = 1...5
let array = Array(range) // Returns [1, 2, 3, 4, 5]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let array = Array(range) // Returns [1, 2, 3, 4, 5]
let array = Array(range)
// Returns [1, 2, 3, 4, 5]


```swift
let array = [1, 2, 3, 4, 5]
let slice = array[1...3] // Returns [2, 3, 4]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let slice = array[1...3] // Returns [2, 3, 4]
let slice = array[1...3]
// Returns [2, 3, 4]


## Range methods

Ranges do have a set of methods that can be used to work with them.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Ranges do have a set of methods that can be used to work with them.
Ranges have a set of methods that can be used to work with them.

The chess game will be played on an eight-square wide and eight-square long board.
The squares are identified by a letter and a number.

## 1. Define rank & file range
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## 1. Define rank & file range
## 1. Define rank and file range

The game will have to check if a square is valid.
A square is valid if the rank and file are within the ranges of the ranks and files.

Define the `isValidSquare(rank:file:)` method that takes the arguments `rank` that holds an int of the rank and `file` that holds a char of the file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is file a char, character or String?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String, I relized I wrote the exercise but while implementing I changed it without updating the docs

The squares are formed as a string of the rank and file, e.g. "1A", "8B", "4G", etc.
To get the row of a square, the game will have to calculate the index of the first square of the row.

Define the `getRow(rank:)` method that takes the argument `rank` that holds an int of the rank.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Define the `getRow(rank:)` method that takes the argument `rank` that holds an int of the rank.
Define the `getRow(rank:)` method that takes the argument `rank` that holds an `int` of the rank.

```swift
let board = ["1A", "1B", "1C", "1D", "1E", "1F", "1G", "1H", "2A", ..., "8H"]
getRow(board, rank: 1)
// returns ["1A", "1B", "1C", "1D", "1E", "1F", "1G", "1H"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// returns ["1A", "1B", "1C", "1D", "1E", "1F", "1G", "1H"]
// Returns ["1A", "1B", "1C", "1D", "1E", "1F", "1G", "1H"]


```swift
let array = [1, 2, 3, 4, 5]
let slice = array[1...3] // Returns [2, 3, 4]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't match the above intro doc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants