Tell us what’s happening:
Alright…I am stuck. When I console.log my code, it appears that test 3,4,5,6 (in the list of tests) are not looping through all the way. The other tests pass. I have worked out the code manually on paper and do not see why this is happening.
For example, the second to last test passes [0, 1, 2, 3, 4, 5, 6, 7, 8] as the first argument, and 4 as the second argument. It should return [0, 1, 2, 3], [4, 5, 6, 7], [8]. But I am getting [0,1,2,3,],[4,5,6,7] with just an empty array at the end.
Any ideas as to what is happening is appreciated!
Thanks,
David
Your code so far
function chunkArrayInGroups(arr, size) {
var newArray = [];
var startCut = 0;
var endCut = size;
for (i = 0; i < arr.length/size; i++) {
newArray.push(arr.slice(startCut, endCut));
startCut = startCut + size;
endCut = size + size;
}
console.log(newArray);
}
chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.88 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/chunky-monkey