mirror of
https://github.com/MessageKit/MessageKit.git
synced 2026-02-06 19:03:19 +00:00
Merge pull request #1598 from cd17822/patch-1
Don't error out when shuffling empty arrays
This commit is contained in:
@@ -223,6 +223,10 @@ public extension Array {
|
||||
Shuffle the array in-place using the Fisher-Yates algorithm.
|
||||
*/
|
||||
mutating func shuffle() {
|
||||
if count == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for i in 0..<(count - 1) {
|
||||
let j = Int(arc4random_uniform(UInt32(count - i))) + i
|
||||
if j != i {
|
||||
|
||||
Reference in New Issue
Block a user