将数组内容打乱

// 返回min到max中的一个随机数
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
}
function shuffle(arr) {
for (let i = 0; i < arr.length; i++) {
let j = getRandomInt(0, i)
let t = arr[i]
arr[i] = arr[j]
arr[j] = t
}
return arr
}

猜你喜欢

转载自www.cnblogs.com/victory820/p/9853638.html
今日推荐