function group(array, subGroupLength) {
let index = 0;
let newArray = [];
while(index < array.length) {
newArray.push(array.slice(index, index += subGroupLength));
}
return newArray;
}
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let groupArr = group(arr, 3);
console.log(groupArr) // [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]