Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Shuffle an Array in 1 line, 108 bytes of JavaScript
function shuffle(set){
for (var c=set.slice(0),o=[],m=Math; c.length > 0; o.push(c.splice(m.floor(m.random() * c.length), 1)[0]));
return o;
with (Math)
for (
// c becomes shallow copy of array
// o is output
var c=set.slice(0),o=[];
c.length > 0;
// slice random entry from c, push it to o (splice always returns arrays, so push its first indice)
o.push(c.splice(floor(random() * c.length), 1)[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment