// 打乱数组
function shuffle(data){
let startIndex = 0,
endIndex = length = data.length - 1;
while(endIndex){
let index = Math.floor(Math.random()*length);
[data[index], data[endIndex]] = [data[endIndex], data[index]];
endIndex--;
}
}
// 具有负数或重复值的数据除外,使用这种方式似乎比其他排序更快一些。
var obj = {};
var arr = Array.from({length:1e5},(item,index)=>index);
shuffle(arr);
console.time();
arr.forEach(item => { obj[item] = item });
console.log(Object.values(obj));
console.timeEnd();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…