Chunky Monkey: Why **a** and **temp** is not an array?

Why a and temp is not an array? Please explain it to me!
Thanks!

Your code so far


function chunkArrayInGroups(arr, size) {
  // Break it up.
  let temp = [];
  let num = arr.length / size;

  for(let i = 0; i < num; i++){
    let a = [];
    a.push(arr.slice(0, size));
    console.log("a: " + a);
    temp.push(a);
    console.log("temp: " + temp);
    arr.splice(0, size);
  }

  return temp;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/chunky-monkey

a and temp are arrays, where do you see that they aren’t?

but you have an other issue in this case: instead of console.log(...) try using console.log(JSON.stringify(...)) and you will see

1 Like

Nice!

Update my code:

for(let i = 0; i < num; i++){
    let a = [];
    a = arr.slice(0, size);
    temp.push(a);
    arr.splice(0, size);
}

Thank @ilenia so much!

Then you don’t need the line with let a = [];, make it one with the next line

1 Like