You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Shuffle/README.markdown
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ This code works just fine but it's not very efficient. Removing an element from
37
37
38
38
## The Fisher-Yates / Knuth shuffle
39
39
40
-
Here is a muchimproved version of the shuffle algorithm:
40
+
Here is a much-improved version of the shuffle algorithm:
41
41
42
42
```swift
43
43
extensionArray {
@@ -52,7 +52,7 @@ extension Array {
52
52
}
53
53
```
54
54
55
-
Again, this picks objects at random. In the naive version we placed those objects into a new temporary array so we could keep track of which objects were already shuffled and which still remained to be done. In this improved algorithm, however, we'll move the shuffled objects to the end of the original array.
55
+
Again, this picks objects at random. In the naive version, we placed those objects into a new temporary array so we could keep track of which objects were already shuffled and which still remained to be done. In this improved algorithm, however, we'll move the shuffled objects to the end of the original array.
56
56
57
57
Let's walk through the example. We have the array:
58
58
@@ -116,7 +116,7 @@ The `shuffledArray()` function first creates a new array with `n` zeros. Then it
116
116
117
117
For this function, `The condition that checks if j ≠ i may be omitted in languages that have no problems accessing uninitialized array values, and for which assigning is cheaper than comparing.`, you can check it in wiki. And also remove checking logic will optimise performance.
118
118
119
-
The algoritm is quite clever and I suggest you walk through an example yourself, either on paper or in the playground. (Hint: Again it splits the array into two regions.)
119
+
The algorithm is quite clever and I suggest you walk through an example yourself, either on paper or in the playground. (Hint: Again it splits the array into two regions.)
0 commit comments