Last active
December 24, 2015 23:38
-
-
Save binnng/6881326 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
var arr = [1, 2, 3, 4, 5]; | |
arr.sort(function (a, b) { | |
return Math.random()>.5 ? -1 : 1;//用Math.random()函数生成0~1之间的随机数与0.5比较,返回-1或1 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment