快速的让⼀个数组乱序
该方法数组长度足够大的话会影响效率
var arr = [1,2,3,4,5,6,7,8,9,10];
arr.sort(()=>{
return Math.random() - 0.5;
})
最优方案
Array.prototype.shuffle = function() {
for(var j, x, i = this.length; i; j = parseInt(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x);
return this;
};