Last active
February 24, 2017 09:37
-
-
Save fuchao2012/da222ababcd0c71cbe8700fee0dc1f4c to your computer and use it in GitHub Desktop.
Random Array
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
//Fisher-Yates 舒服了 | |
Array.prototype.shuffle=function(){ | |
let results = [], temp, acc = this.length >>> 0 | |
while(acc > 0){ | |
temp = (Math.random() * acc--)>>>0 | |
[this[acc],this[temp]] = [this[temp], this[acc]] | |
} | |
return this | |
} | |
//Little Shuffle | |
Array.prototype.shuffle = function(){ | |
return this.sort(()=>.5 - Math.random()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment