Skip to content

Instantly share code, notes, and snippets.

@remy
Forked from madrobby/gist:333764
Created March 16, 2010 13:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save remy/333954 to your computer and use it in GitHub Desktop.
Save remy/333954 to your computer and use it in GitHub Desktop.
Beautiful one line array shuffle
// pure JS
function shuffle(array) {
return array.sort(function(){
return .5 - Math.random();
});
}
// with Prototype.js you can do
function shuffle(array){
return array.sortBy(Math.random);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment