Skip to content

Instantly share code, notes, and snippets.

@Aqours
Created November 7, 2017 12:17
Show Gist options
  • Save Aqours/1670c0dce1907ffeb4ac4540eae8089f to your computer and use it in GitHub Desktop.
Save Aqours/1670c0dce1907ffeb4ac4540eae8089f to your computer and use it in GitHub Desktop.
随机打乱数组
/**
* @param {Array} list
* @return {Array}
*/
function shuffle(list) {
var len = list.length;
var randomIndex, buffer;
while (len) {
randomIndex = Math.floor(Math.random() * len);
buffer = list[--len];
list[len] = list[randomIndex];
list[randomIndex] = buffer;
}
return list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment