Created
December 11, 2018 08:58
-
-
Save duhaime/2c2510d535063e8d1b5c02e1d7cb31b4 to your computer and use it in GitHub Desktop.
Fisher-Yates Shuffle
This file contains 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(l) { | |
var plucked = [], | |
len = l.length; | |
while (plucked.length < len) { | |
var idx = parseInt(Math.random() * l.length); | |
plucked.push( l.splice(idx, 1)[0] ); | |
} | |
return plucked; | |
} | |
var l = [1,2,3,4,5]; | |
l = shuffle(l); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment