newarr=[1,2,3,4,5,6]
function randomsort(a,b){
return Math.random()>0.5?-1:1;
}
//用Math.random()函数生成0~1之间的随机数与0.5比较,返回-1或1
newarr = newarr.sort(randomsort);
console.log(newarr);
newarr=[1,2,3,4,5,6]
function randomsort(a,b){
return Math.random()>0.5?-1:1;
}
//用Math.random()函数生成0~1之间的随机数与0.5比较,返回-1或1
newarr = newarr.sort(randomsort);
console.log(newarr);