
const arr = [1, 2, 3, 4, 5, 6, 7, 8];
const groupSize = 3;
const groups = arr.reduce((accumulator, currentValue, index) => {
if (index % groupSize === 0) {
accumulator.push([]);
}
accumulator[accumulator.length - 1].push(currentValue);
return accumulator;
}, []);
console.log(groups); // [[1, 2, 3], [4, 5, 6], [7, 8]]



