博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

javascript 中根据sort 方法随机数组 (Math.random)

Posted on 2016-07-04 16:55  绝交  阅读(441)  评论(0编辑  收藏  举报

 

var arr = [1,2,3,4,5,6,7,8,9,10];

function Arandom(a,b){

  return (Math.random() > 0.5) ? 1 : -1;;

}

arr.sort(Arandom);

console.log(arr)