# Chunky monkey 1 test wont pass

having trouble with one of the last test heres my code its very repetive

``````function chunkArrayInGroups(arr, size) {
// Break it up.

var newArr = [];
for(var i = 0;i<size;i = i + size){
newArr.push(arr.slice(i,size));
newArr.push(arr.slice(i+size, size+size));
if(arr.length > size+size){
newArr.push(arr.slice(i+size+size, size+size+size));
}

}

return newArr;
}
``````

thanks for the help

I can’t quite follow your logic. You are looping until i is equal to size? That is the size of the new subarrays, not the size of the arr that was passed to you. I think you need to loop to i < arr.size. It looks to me like you are trying to hard code the pushing of the subarrays instead of doing it algorithmically. A quick console.log check will show that you are only looping once. This makes sense because `for(var i = 0; i<size; i = i + size)` ensures it. On second pass, i will be equal to size (size+0=size) so no matter what the size of size, you will only ever get one pass. You try to compensate for that with multiple push statements and a tagged if statement. But what would you do if size was 127 and arr had 512 elements? I think your thinking on this is off.

Here’s how I approached it in pseudocode:

``````define an empty array called hold
define an empty array called final
loop i from 0 to the length of arr, incrementing by 1
if i%size is not equal to size-1  // we haven't filled the subarray
push arr[i] onto hold
else // subarray is full
push arr[i] onto hold
push hold onto final   // adding the filled subarray hold
reset hold to an empty array   // getting ready for next subarray
end loop

if hold.length is not 0  // leftover, incomplete subarray
push hold onto final

return final
``````

There might be a more elegant solution, but this is straightforward and it’s what I came up with as I was trying to race through the FE stuff.

thanks it worked that really helped