File tree 1 file changed +4
-4
lines changed
1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ extension Array {
12
12
var temp = [Element ]()
13
13
while ! isEmpty {
14
14
let i = random (count)
15
- let obj = removeAtIndex ( i)
15
+ let obj = remove ( at : i)
16
16
temp.append (obj)
17
17
}
18
18
self = temp
@@ -44,7 +44,7 @@ Here is a much improved version of the shuffle algorithm:
44
44
``` swift
45
45
extension Array {
46
46
public mutating func shuffle () {
47
- for i in ( count - 1 ). stride ( through : 1 , by : -1 ) {
47
+ for i in stride ( from : count - 1 , through : 1 , by : -1 ) {
48
48
let j = random (i + 1 )
49
49
if i != j {
50
50
swap (& self [i], & self [j])
@@ -96,8 +96,8 @@ There is a slight variation on this algorithm that is useful for when you want t
96
96
Here is the code:
97
97
98
98
``` swift
99
- public func shuffledArray (n : Int ) -> [Int ] {
100
- var a = [Int ](count : n, repeatedValue : 0 )
99
+ public func shuffledArray (_ n : Int ) -> [Int ] {
100
+ var a = [Int ](repeating : 0 , count : n )
101
101
for i in 0 ..< n {
102
102
let j = random (i + 1 )
103
103
if i != j {
You can’t perform that action at this time.
0 commit comments