Hi there,
I passed the Chunky Monkey challenge with this code (I have commented the parts at the end of lines 3 & 4 that were correct but I don’t fully understand how they work):
function chunkArrayInGroups(arr, size) {
var newArray = [];
for (var i = 0; i < arr.length; i = i+size) { // i = i+ size
newArray.push(arr.slice(i, i + size)); // i, i + size
}
return newArray;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
My aim had been to try and solve it as a for loop and then ‘upgrade’ it to use reduce method. I’m just finding it SO hard to understand!
I’ve been reading and reading about reduce and trying to see how it relates to this particular challenge but to be honest I feel pretty lucky to even have passed it with a for loop let alone .reduce.
Any advice that could be given as to exactly how my for loop will translate to .reduce I’d be very grateful
Thanks