Chunky Monkey - Correct Output but not getting accepted by the site

Tell us what’s happening:
using console.log I’m getting proper output but the code is not getting accepted by free code camp

Your code so far


function chunkArrayInGroups(arr, size) {
  // Break it up.
  let j = arr.length/size;

  let a = 0;

  let arr1 = arr.splice(a,arr.length);

  if (arr1.length % size !== 0){

    for (let i = 0; i <= j; i++){

      let subArr = arr1.splice(a, size);

      arr.push(subArr);

      subArr = [];

    }

    arr.push(arr1);

  }

  else{

    for (let i = 0; i <= j; i++){

      let subArr = arr1.splice(a, size);

      arr.push(subArr);

      subArr = [];

    }

  }
  
  return arr;


}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36.

Link to the challenge:

Your output is not correct, check it again.

Consider what this gives you…

let j = arr.length / size;

And how looping an array works which the knowledge that arrays are zero-based (link).

1 Like

Your output for this code is [["a","b"],["c","d"],[]] when it should be just [["a","b"],["c","d"]]

Thanks lot for your time. I got the mistake!:slightly_smiling_face: