Skip to content
This repository has been archived by the owner on Mar 29, 2018. It is now read-only.

used shuffle() to shuffle in shuffled() #16

Merged
merged 2 commits into from
Jul 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions ExSwift/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,7 @@ extension Array {
func shuffled () -> Array {
var shuffled = self
shuffled.unshare()

// Fisher-Yates shuffle
for i in 0..self.count {
let j = Int.random(max: i)
if j != i {
shuffled[i] = shuffled[j]
}
shuffled[j] = self[i]
}
shuffled.shuffle()

return shuffled
}
Expand Down
11 changes: 10 additions & 1 deletion ExSwift/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension String {
* @return Charaters at the specified indexes (converted to String)
*/
subscript (indexes: Int...) -> String[] {
return at(reinterpretCast(indexes))
return at(indexes)
}

/**
Expand All @@ -57,6 +57,15 @@ extension String {
return indexes.map { self[$0]! }
}

/**
* Returns the characters at the specified indexes
* @param indexes
* @return Array of characters (as String)
*/
func at (indexes: Int[]) -> String[] {
return indexes.map { self[$0]! }
}

/**
* Returns an array of strings, each of which is a substring of self formed by splitting it on separator
* @param separator
Expand Down