Chunky Monkey - What Am I Doing Wrong?

Chunky Monkey - What Am I Doing Wrong?
0

Hi,
I’m working on the “Chunky Monkey” challenge -
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/chunky-monkey
My “Chunky Monkey” code seems to work on the Chrome console (and when I use console.log on the FCC site), but it doesn’t pass any of the tests.

  1. In my loop, I’m taking the whole ‘slice’ of the original array at once (starts with the value of i and stops with i+size) and assigning it the variable of ‘newSubArray.’
  2. I’m ‘pushing’ that ‘newSubArray’, as an array, into the new array (called ‘newArr’).
  3. With console.log, it’s complete, I’m displaying each sub-array separately. It seems to work each time, but it’s not passing the FCC tests at all, so I must be missing something.

What am I doing wrong?
Thanks!

function chunkArrayInGroups(arr, size) {
 
 let newArr = [];
 let newSubArr = [];
  for (let i = 0; i < arr.length; i+= size){
   newSubArr = arr.slice(i,i+size);
   newArr.push([newSubArr]);
   };
   
  //just for checkin' :
 for (let j = 0; j<(arr.length/size); j++){
   console.log(newArr[j]);
 }
 console.log(newArr);
  return newArr;
}
 
chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4)

isn’t newSubArr already an array? try using the browser console and see what your function is returning (or a code editor like repl.it)
the limitations of freecodecamp console make easier to miss this issue

You caught it! Since newSubArr is already an array, I shouldn’t have put it in brackets when I pushed it into the new array.
It works now.