Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5f64dc0

Browse files
authored
Merge pull requestkodecocodes#273 from TheIronBorn/patch-5
fix for Swift 3
2 parentsca7a01f +bf24ad0 commit5f64dc0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

‎Shuffle/README.markdown‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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
4545
extensionArray {
4646
publicmutatingfuncshuffle() {
47-
for iin(count-1).stride(through:1,by:-1) {
47+
for iinstride(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
9696
Here is the code:
9797

9898
```swift
99-
publicfuncshuffledArray(n:Int)-> [Int] {
100-
var a= [Int](count: n,repeatedValue:0)
99+
publicfuncshuffledArray(_n:Int)-> [Int] {
100+
var a= [Int](repeating:0,count: n)
101101
for iin0..<n {
102102
let j=random(i+1)
103103
if i!= j {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp