Created
March 6, 2014 02:41
-
-
Save StuPig/9381226 to your computer and use it in GitHub Desktop.
shufle js洗牌算法
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
// 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