Skip to content

Instantly share code, notes, and snippets.

@goldnetonline
Created September 2, 2016 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goldnetonline/19a61b857ac20621dd7555d236209964 to your computer and use it in GitHub Desktop.
Save goldnetonline/19a61b857ac20621dd7555d236209964 to your computer and use it in GitHub Desktop.
Javascript Array Shuffle
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