Created
November 21, 2014 11:29
-
-
Save lengshuiyulangcn/b6c09eaa8b571c73510a to your computer and use it in GitHub Desktop.
Array#shuffle in js
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
//Array#shuffle | |
Array.prototype.shuffle = function() { | |
var i = this.length; | |
while(i){ | |
var j = Math.floor(Math.random()*i); | |
var t = this[--i]; | |
this[i] = this[j]; | |
this[j] = t; | |
} | |
return this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment