Skip to content

Instantly share code, notes, and snippets.

@ironboy
Created September 4, 2015 20:37
Show Gist options
  • Select an option

  • Save ironboy/e687921da5cbb7612bd2 to your computer and use it in GitHub Desktop.

Select an option

Save ironboy/e687921da5cbb7612bd2 to your computer and use it in GitHub Desktop.
Shuffle an array - return a shuffled copy (keep original intact)
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