Skip to content

Instantly share code, notes, and snippets.

@StuPig
Created March 6, 2014 02:41
Show Gist options
  • Save StuPig/9381226 to your computer and use it in GitHub Desktop.
Save StuPig/9381226 to your computer and use it in GitHub Desktop.
shufle js洗牌算法
// more on: http://jsperf.com/js-shuffle-test/2
/**
* 数组洗牌算法
* @param arr
*/
function shuffle(arr) {
var s = [];
while (arr.length) s.push(arr.splice(Math.random() * arr.length, 1)[0]);
arr = arr.concat(s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment