js 手写随机数组 洗牌算法 数组乱序
const shuffle = arr => {
let len = arr.length
let rand = 0
while (len) {
rand = Math.floor(Math.random() * len--)
;[arr[len], arr[rand]] = [arr[rand], arr[len]]
}
return arr
}
console.log(shuffle([1, 2, 3, 4, 5, 6]));