let random = arr => {
arr = [...arr]
let len = arr.length
for (let i = 0; i < arr.length; i++) {
let random = Math.floor(Math.random() * (len - i)) + i
;[arr[i], arr[random]] = [arr[random], arr[i]]
}
return arr
}
let a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
let ress = random(a)
console.log(ress,a)
var arr=[1,3,5,6,7,9,8];
// 迭代
function foo(arr){
var cloneArr=arr.concat();//拷贝数组
var result=[];
var len=cloneArr.length;
for(var i=0;i<len;i++){
var index=Math.floor(Math.random()*cloneArr.length);
result=result.concat(cloneArr[index]);
}
return result;
}
for(var i=0;i<10;i++){
console.log(foo(arr))
}
console