JSFiddle - React, Tailwind, and code Playground
JavaScript
let endPosition = 0;
let restGroup = [];
let fiveBlocks = [];
let allArray = [[1,2,3,4,5,6], [1,2,3]];
const MAX_BLOCK_LENGTH = 5;
for (let i = 0; i < allArray.length; i++) {
for (let x = 0; x < allArray[i].length; x++) {
if(allArray[i].length < MAX_BLOCK_LENGTH) {
restGroup.push(allArray[i][x])
} else {
for(let blocksGroup = 1;blocksGroup <= (allArray[i].length / 5); blocksGroup++){
let y = ( blocksGroup * MAX_BLOCK_LENGTH ) - MAX_BLOCK_LENGTH;
for(y; y < MAX_BLOCK_LENGTH * blocksGroup; y++){
fiveBlocks.push(allArray[i][x])
}
if((allArray[i].length - y) < MAX_BLOCK_LENGTH){
endPosition = y;
}
}
for (endPosition; endPosition < allArray[i].length; endPosition++){
restGroup.push(allArray[i][endPosition])
}
}
}
}
console.log(fiveBlocks)
console.log(restGroup)