Created
March 31, 2013 15:38
-
-
Save foldi/5281034 to your computer and use it in GitHub Desktop.
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
/** | |
* Randomly reorders the contents of an array in place. | |
* @author blixt (https://github.com/blixt) | |
* @param {Array.<Object>} arr An array. | |
* @returns {Array.<Object>} The same array that was passed in, | |
* now shuffled. | |
*/ | |
function shuffleArray(arr) { | |
var i, j, item; | |
for (i = arr.length - 1; i > 0; i--) { | |
j = Math.round(Math.random() * i); | |
item = arr[i]; | |
arr[i] = arr[j]; | |
arr[j] = item; | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment