I’m trying to understand the explanation given for advanced code solution 2 in the answer guide for this challenge: freeCodeCamp Algorithm Challenge Guide: Chunky Monkey.
The solution…
function chunkArrayInGroups(arr, size) {
var newArr = [];
while (arr.length) {
newArr.push(arr.splice(0,size));
}
return newArr;
}
…seems to be missing a step or two. Can I assume that if the condition in the while loop is arr.length, then JavaScript knows from the initial splice size how big each subsequent splice should be?