Created
October 27, 2017 08:15
-
-
Save nanomen/2df0927df5cae98595546bf8cc7ea51c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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