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

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

#1

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:


#2

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;

#3

I see, many thanks for your help!!!

Was scratching my head for this one.

Thanks!