I’m not sure if i’m missing something or not. In the '" Basic Algorithm Scripting: Chunky Monkey" my code
returns the expected result ,but it doesn’t pass any test. What am i missing?
function chunkarrInGroups(arr, size) {
let arr1 = [];
let arr2 = [];
for (let i = 0; i < arr.length; i++) {
arr1.push(arr[i]);
if (arr1.length == size || arr.length == i+1) {
arr2.push(arr1);
arr1 = [];
}
}
// Break it up.
console.log(arr2);
return arr2;
}
chunkarrInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2);