Skip to content

Instantly share code, notes, and snippets.

@clm-a
Created April 1, 2011 14:20
Show Gist options
  • Save clm-a/898215 to your computer and use it in GitHub Desktop.
Save clm-a/898215 to your computer and use it in GitHub Desktop.
Shuffle a javascript array
Array.prototype.shuffle = function( b ) {
var i = this.length, j, t;
while( i ) {
j = Math.floor( ( i-- ) * Math.random() );
t = b && typeof this[i].shuffle!=='undefined' ? this[i].shuffle() : 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