Skip to content

Instantly share code, notes, and snippets.

@nanomen
Created October 27, 2017 08:15
Show Gist options
  • Save nanomen/2df0927df5cae98595546bf8cc7ea51c to your computer and use it in GitHub Desktop.
Save nanomen/2df0927df5cae98595546bf8cc7ea51c to your computer and use it in GitHub Desktop.
(list => {
const
rand = max => Math.floor(Math.random() * (max + 1) ),
shuffle = __list__ => {
let index = __list__.length - 1;
for (; index > 0; index--) {
let randIndex = rand(index);
[ __list__[index], __list__[randIndex] ] = [ __list__[randIndex], __list__[index] ];
}
return __list__;
};
log(
shuffle(list)
);
})([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment