Created
September 4, 2015 20:37
-
-
Save ironboy/e687921da5cbb7612bd2 to your computer and use it in GitHub Desktop.
Shuffle an array - return a shuffled copy (keep original intact)
This file contains hidden or 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
| Array.prototype.shuffle = function(){ | |
| var x = this.slice(), y = []; | |
| while(x.length){y.push(x.splice(Math.floor(Math.random()*x.length),1)[0]);} | |
| return y; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment