代码:
let arr = [1, 2, 3, 4, 5]
function upsetArr(arr) {
let newArr = []
let i = 0
while (arr.length) {
let index = parseInt(Math.random() * arr.length)
newArr[i] = arr[index]
arr.splice(index, 1)
i++
}
return newArr
}
console.log(upsetArr(arr))