Skip to content

Instantly share code, notes, and snippets.

@jeremenichelli
Last active August 29, 2015 14:17
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 jeremenichelli/1c5a96d820bdd785601b to your computer and use it in GitHub Desktop.
Save jeremenichelli/1c5a96d820bdd785601b to your computer and use it in GitHub Desktop.
Shuffle arrays
shuffle = function (arr) {
var newArr = [],
origArr,
len;
if (!!arr && ) {
origArr = arr.slice();
len = arr.length;
while (len) {
newArr.push(origArr.splice(parseInt(Math.random() * len--), 1)[0]);
}
} else {
return arr || null;
}
return newArr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment