Created
March 5, 2018 17:21
-
-
Save HiroAgustin/584c4b855678bc285898300c309ff24e 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
function shuffle (array) { | |
let remaining = array.length | |
// While there remain elements to shuffle. | |
while (remaining) { | |
// Pick a remaining index. | |
let index = Math.floor(Math.random() * remaining--) | |
// And swap it with the current element. | |
let item = array[remaining] | |
array[remaining] = array[index] | |
array[index] = item | |
} | |
return array | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Better? Worse? IDK, definitely messier.