//代码题: 部分翻转
// 输入:
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const n = 3;
// 输出:
//[10, 7, 8, 9, 4, 5, 6, 1, 2, 3];
//方法1
function reverse(data,n) {
var result = [];
for(var i=0,len=data.length;i<len;i+=n){
result.push(data.slice(i,i+n));
}
console.log(result.reverse().flat())
}
reverse(arr,n)
//方法2
function group(array, subGroupLength) {
var index = 0;
var newArray = [];
while(index < array.length) {
newArray.push(array.slice(index, index += subGroupLength));
}
return newArray;
}
var groupedCountries = group(arr, n);
console.log(groupedCountries.reverse().flat())
//思路lodash chunk
console