Skip to content

Instantly share code, notes, and snippets.

@binnng
Last active December 24, 2015 23:38
Show Gist options
  • Save binnng/6881326 to your computer and use it in GitHub Desktop.
Save binnng/6881326 to your computer and use it in GitHub Desktop.
随机打乱数组
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