[Basic Algorithm Scripting: Chunky Monkey] Function returns correct arrays but doesn't pass the tests

[Basic Algorithm Scripting: Chunky Monkey] Function returns correct arrays but doesn't pass the tests
0.0 0

#1

Hi all,

I came up with the following code which - as per console - returns the correct arrays.

However, none of the tests is passed. Can anyone tell my why?

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

  let tArr = [[]];
  let j = 0;
  let k = 0;

  for (let i = 0; i < arr.length; i++) {
    if (j >= size) {
      tArr.push([]);
      k ++;
      j = 0;
    }
    tArr[k][j] = arr[i];
    j++;
  }
  console.log(tArr);
  return arr;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);

Kind Regards


#2

You’re returning the original array (arr) rather than tArr :wink:


#3

Oh gee - it’s early in the morning. :smiley:

Thank you very much! I even double checked if I properly return arr:roll_eyes: