This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
Randomize array element order in-place. | |
Using Fisher-Yates shuffle algorithm. | |
### | |
Array.prototype.shuffle = -> | |
for i in [(@length - 1) .. 0] | |
j = Math.floor(Math.random() * (i + 1)) | |
[@[i], @[j]] = [@[j], @[i]] | |
@ |