This function will take an array and chunk it into separate arrays, create an offset at the beginning and wrap that in another array. The problem I have is not all of the numbers from the original array (arr1) are included in the chunks. You can see the output in the link I have provided below. It misses out numbers 5, 13, 21, 29 and 30. Can anyone explain why this happens?
function chunkifyArray(input, chunkSize, offset) {
const output = [];
let tmp = offset ? new Array(offset).fill('') : [];
for(var i = 0; i < input.length; i++){
if (tmp.length < chunkSize) {
tmp.push(input[i]);
} else {
output.push(tmp);
tmp = [];
}
}
return output;
}
var arr1 = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30'];
console.log(chunkifyArray(arr1, 7, 3));