Chunky Monkey - Need help, can anyone please check my code? Thank you!

Tell us what’s happening:

Your code so far

function chunkArrayInGroups(arr, size) {
arr3=[];
  for(i=1;i<=arr.length/size;i++){
    arr3.push(arr.slice(size*(i-1),size*i));
      } 
  if(arr.length%size===0){
return arr3;}else{
  arr4 = arr.slice(size*(i-1),size*(i-1)+arr.length%size);
  return arr3.push(arr4);
}
}


chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36.

Link to the challenge:

As per documentation about push (bolded the relevant part):

The push() method adds one or more elements to the end of an array and returns the new length of the array.

Or in this case

return arr3.push(arr4);

Will return 3 which is the new length of the array.
Probably what you want to do is to push the new value in, and then return the array:

arr.push(newVal);
return arr;
1 Like

I see, many thanks for your help!!!

Was scratching my head for this one.

Thanks!