Tell us what’s happening:
Your code so far
function chunkArrayInGroups(arr, size) {
// Break it up.
let newArr = [];
let i = 0;
let z = arr.length % size;
while (i <= arr.length){
newArr.push(arr.slice(i , size))
i = i + size;
size = size + size;
} // while loop ends here
if (z!= 0){
newArr.push(arr.slice(-z));
}
return newArr;
}
chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/chunky-monkey
I don’t know why I can’t pass
chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2)
chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4)
chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2)
But chunkArrayInGroups(["a", "b", "c", "d"], 2)
works.