Hi everyone, I’m wondering if anyone can tell me why my code isn’t passing any of the tests?
So I tested it on the chrome console and it looks like it achieves the desired result.
function chunkArrayInGroups(arr, size) {
let spliced;
let finalArr = [];
while (arr.length > size) {
spliced = arr.splice(0, size);
finalArr.push([]);
finalArr[finalArr.length-1].push(spliced);
}
if (arr.length <= size) {
finalArr.push([]);
finalArr[finalArr.length-1].push(arr);
}
return finalArr;
}
chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4);
This is the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/chunky-monkey/