Created
July 10, 2014 02:16
-
-
Save tanshio/2fdd114b1b74eb2972c8 to your computer and use it in GitHub Desktop.
Fisher–Yates
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
shaffle = function(arr){ | |
var n = arr.length; | |
for(var i = n - 1; i > 0; i--) { | |
var j = Math.floor(Math.random() * (i + 1)); | |
var tmp = arr[i]; | |
arr[i] = arr[j]; | |
arr[j] = tmp; | |
} | |
return arr; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment