把数组 arr= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]先乱序打乱输出数组arr1,然后将arr1按倒序的方式排序输出arr2

let arr= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

function disorder(){

for (let i = arr.length; i; i--) {

let j = Math.floor(Math.random() * i);

[arr[i - 1], arr[j]] = [arr[j], arr[i - 1]];

}

return arr;

}

let arr1=disorder(arr)

console.log(arr1)

let arr2=arr1.reverse()

console.log(arr2)

你可能感兴趣的:(把数组 arr= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]先乱序打乱输出数组arr1,然后将arr1按倒序的方式排序输出arr2)