Skip to content

Commit 8585885

Browse files
Wesley-Arringtonjune128
authored andcommitted
Updating To Current Swift Version (#385)
1 parent eeb83e6 commit 8585885

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

contents/bogo_sort/bogo_sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ In code, it looks something like this:
3636
{% sample lang="rs" %}
3737
[import:16-20, lang:"rust"](code/rust/bogosort.rs)
3838
{% sample lang="swift" %}
39-
[import:25-31, lang:"swift"](code/swift/bogosort.swift)
39+
[import:13-19, lang:"swift"](code/swift/bogosort.swift)
4040
{% sample lang="php" %}
4141
[import:11-16, lang:"php"](code/php/bogo_sort.php)
4242
{% sample lang="nim" %}

contents/bogo_sort/code/swift/bogosort.swift

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,15 @@ func isSorted(inputArray: [Int]) -> Bool {
66
return false
77
}
88
}
9-
10-
return true
11-
}
12-
13-
func shuffle(inputArray: inout [Int]) -> [Int] {
14-
var shuffledArray = [Int]()
159

16-
for _ in 0..<inputArray.count {
17-
let rand = Int(arc4random_uniform(UInt32(inputArray.count)))
18-
shuffledArray.append(inputArray[rand])
19-
inputArray.remove(at: rand)
20-
}
21-
22-
return shuffledArray
10+
return true
2311
}
2412

2513
func bogoSort(sortArray: inout [Int]) -> [Int] {
2614
while(!isSorted(inputArray: sortArray)) {
27-
sortArray = shuffle(inputArray: &sortArray)
15+
sortArray.shuffle()
2816
}
29-
17+
3018
return sortArray
3119
}
3220

0 commit comments

Comments
 (0)