Skip to content

Instantly share code, notes, and snippets.

@desmondrawls
Created March 27, 2013 20:08
Show Gist options
  • Save desmondrawls/5257575 to your computer and use it in GitHub Desktop.
Save desmondrawls/5257575 to your computer and use it in GitHub Desktop.
Array shuffling method
Array.prototype.shuffle = function shuffle(){
var tempSlot;
var randomNumber;
for (var i = 0; i != this.length; i++){
randomNumber = Math.floor(Math.random() * this.length);
tempSlot = this[i];
this[i] = this[randomNumber];
this[randomNumber] = tempSlot;
}
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment