Created
September 2, 2016 17:43
-
-
Save goldnetonline/19a61b857ac20621dd7555d236209964 to your computer and use it in GitHub Desktop.
Javascript Array 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
Array.prototype.shuffle = function() { | |
var input = this; | |
for (var i = input.length-1; i >=0; i--) { | |
var randomIndex = Math.floor(Math.random()*(i+1)); | |
var itemAtIndex = input[randomIndex]; | |
input[randomIndex] = input[i]; | |
input[i] = itemAtIndex; | |
} | |
return input; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment