I’m stuck on the Chunky Monkey problem. Below is my code so far. Any hints or ideas on how I can get the 2nd iteration of slice to return into my new array?
function chunkArrayInGroups(arr, size) {
let newArr = [];
for(let i =0; i < arr.length; i += size){
//console.log(arr.slice(i));
let tempArr = arr.slice(i,size);
console.log(tempArr)
if(tempArr.length == size){
newArr.push(arr.slice(i,size));
}
else{
newArr.push(arr.slice(i));
break;
}
}
return newArr;
}
When slice is called for the 2nd time. The method gives me an empty array. I know why……….however I don’t how to use a for loop and the slice method to obtain the items I need for the mew array. Does that make sense?
I’m starting at the 2nd index and slicing two items …problem is my starting index is behind the number items I need to slice. I should be slicing 4 items in my 2nd loop….than 6 items in my final loop. I really don’t know how to iterate the slice method. Does that make sense?