My code is correct for all the problems, but I need help on the logic of this code why it is correct. For this code, I would slice for the first time will be slice(i=0,size), and for the next slice(i+size, size +1) which will give the newArray value when push is [[0,1,2],[3,4,5]].But, how come the array [6] still push inside the newArray? Appreciate you could help me on this logic?
Thank you.
Your code so far
function chunkArrayInGroups(arr, size) {
// Break it up.
var array = [];
var newArray = [];
for (i=0;i<arr.length;i+= size){
newArray.push(arr.slice(i, size+i));
}
return newArray;
}
chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36
.
Link to the challenge: