Last active
August 29, 2015 14:17
-
-
Save jeremenichelli/1c5a96d820bdd785601b to your computer and use it in GitHub Desktop.
Shuffle arrays
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
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