function shuffle(array) {
let length = array.length;
let index;
let temp;
while (length > 0) {
index = Math.floor(Math.random() * length);
temp = array[length - 1];
array[length - 1] = array[index];
array[index] = temp;
length--;
}
return array
}
JavaScript洗牌算法打乱数组元素顺序
最新推荐文章于 2024-11-13 15:29:17 发布