Skip to content

Commit f187a39

Browse files
authored
fix: update various code snippets for consistency and correctness (#856)
1 parent 642adb3 commit f187a39

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ let conceptExerciseTargets: [Target] = conceptExercises.flatMap {
4242
.target(name:"\($0.pascalCased)"),
4343
.product(name: "Numerics", package: "swift-numerics")
4444
],
45-
path:"./exercises/concept/\($0)/Tests",
46-
exclude: ["LinuxMain.swift"])
45+
path:"./exercises/concept/\($0)/Tests"
46+
)
4747
]
4848
}
4949

exercises/practice/diamond/.meta/Sources/Diamond/DiamondExample.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ struct Diamond {
22
static let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".map { $0 }
33

44
static func makeDiamond(letter: Character) -> [String] {
5-
guard let index = alphabet.index(of: letter) else {
5+
guard let index = alphabet.firstIndex(of: letter) else {
66
return []
77
}
88

exercises/practice/grade-school/.meta/Sources/GradeSchool/GradeSchoolExample.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class GradeSchool {
22
var rosters = [Int: [String]]()
33

44
func addStudent(_ name: String, grade: Int) -> Bool {
5-
if rosters.values.contains { $0.contains(name) } {
5+
if rosters.values.contains(where: { $0.contains(name) }) {
66
return false
77
}
88
rosters[grade, default: []].append(name)

exercises/practice/kindergarten-garden/.meta/Sources/KindergartenGarden/KindergartenGardenExample.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ struct Garden {
3030
let sortedChildren = children.sorted(by: <)
3131
let lines = diagram.components(separatedBy: CharacterSet.newlines)
3232
var result = [String: [Plant]]()
33-
var line1 = lines[0].map { String($0) }
34-
var line2 = lines[1].map { String($0) }
33+
let line1 = lines[0].map { String($0) }
34+
let line2 = lines[1].map { String($0) }
3535

3636
var index = 0
3737

exercises/practice/roman-numerals/.meta/Sources/RomanNumerals/RomanNumeralsExample.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extension Int {
22
func toRomanNumeral() -> String {
3-
var arabicToRoman = [1000: "M", 900: "CM", 500: "D", 400: "CD", 100: "C", 90: "XC", 50: "L", 40: "XL", 10: "X", 9: "IX", 5: "V", 4: "IV", 1: "I"]
3+
let arabicToRoman = [1000: "M", 900: "CM", 500: "D", 400: "CD", 100: "C", 90: "XC", 50: "L", 40: "XL", 10: "X", 9: "IX", 5: "V", 4: "IV", 1: "I"]
44
var i = self
55
var s = ""
66
for arabic in arabicToRoman.keys.sorted(by: > ) {

exercises/practice/saddle-points/.meta/Sources/SaddlePoints/SaddlePointsExample.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ struct SaddlePoints {
22
static func saddlePoints(_ matrix: [[Int]]) -> [Position] {
33
var saddlePoints = [Position]()
44
for (rowIndex, row) in matrix.enumerated() {
5-
for (columnIndex, element) in row.enumerated() {
5+
for (columnIndex, _) in row.enumerated() {
66
if isSaddlePoint(matrix, rowIndex, columnIndex) {
77
saddlePoints.append(Position(row: rowIndex + 1, column: columnIndex + 1))
88
}

exercises/practice/sum-of-multiples/.meta/Sources/SumOfMultiples/SumOfMultiplesExample.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ func toLimit(_ limit: Int, inMultiples: [Int]) -> Int {
22
guard limit > 0 else { return 0 }
33
var multiples = Set(inMultiples)
44

5-
if let indexOfZero = multiples.index(of: 0) {
5+
if let indexOfZero = multiples.firstIndex(of: 0) {
66
multiples.remove(at: indexOfZero)
77
}
88

0 commit comments

Comments
 (0)