This is the solution I came up with: every other test case seems to be passing except for this one:: chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2). please help!!
Your code so far
function chunkArrayInGroups(arr, size) {
// Break it up.
let newArr = [];
for ( let i = 0; i < arr.length; i++ ) {
if ( arr.length > size ) {
newArr.push( arr.splice(0, size) );
}
}
newArr.push(arr);
return newArr;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
To expand a bit on what Randell said, this is a good example of why you want to avoid mutating an array that you are currently iterating over. Because the values at an index change with every iteration, you can’t just march through an iterator the way that you expect to.