File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ extension Array {
1212 var temp = [Element ]()
1313 while ! isEmpty {
1414 let i = random (count)
15- let obj = removeAtIndex ( i)
15+ let obj = remove ( at : i)
1616 temp.append (obj)
1717 }
1818 self = temp
@@ -44,7 +44,7 @@ Here is a much improved version of the shuffle algorithm:
4444``` swift
4545extension Array {
4646 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 ) {
4848 let j = random (i + 1 )
4949 if i != j {
5050 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
9696Here is the code:
9797
9898``` 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 )
101101 for i in 0 ..< n {
102102 let j = random (i + 1 )
103103 if i != j {
You can’t perform that action at this time.
0 commit comments