描述:数组长度66,存放数据为[1,2,3,4....,65,66],每次运算如下:[1,2,3...,33],[34,35,36...66],推入另外一个数组[1,34,2,36,3,36,....33,66].问多少次运算后,数据还原为[1,2,3,4....,65,66].
let originArr = Array.from(new Array(67).keys())
originArr.shift(0)
let num = 0
function mixArrMethod(first,second){
let resultArr = []
for(let i = 0;i < first.length;i++){
resultArr.push(first[i])
resultArr.push(second[i])
}
return resultArr
}
function reBackArr(arr){
const len = arr.length/2;
let first = arr.slice(0,len)
let second = arr.slice(len)
let mixArr = mixArrMethod(first,second)
if(mixArr.toString() === originArr.toString()){
console.log(num)
}else{
num++
reBackArr(mixArr)
}
}
reBackArr(originArr)