Tell us what’s happening:
Hello. So I came up with the following code to Chunky Monkey. For some reason the last two elements are omitted each time, and also if the last array would not have two elements, it is also omitted. I think it is because the end argument of slice needs to be larger than the length of the array, which would by the end of the for loop be 2, when indexes 4 and 5 are left in forArr. But it is still just equal to the array length. I tried multiple codes but am at a loss. Please tell me what I am missing here.
Your code so far
function chunkArrayInGroups(arr, size) {
// Break it up.
var m = arr.join("");
var newArr = [];
var forArr = arr;
var n=0;
for (i=0;i<forArr.length;i++) {
newArr.push(forArr.slice(0,size));
for (j=0;j<size;j++) {
forArr.shift();
}
}return newArr;
}
chunkArrayInGroups(["a", "b", "c", "d","e","f"], 2);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/chunky-monkey