Chunky Monkey recursive solution not getting accepted

Recursive solution not able to pass even a single test case :


var globalArr = [];
function chunkArrayInGroups(arr, size) {
  if(arr.length <= size) {
    return globalArr.push(arr) && globalArr;
  return globalArr.push(arr.slice(0, size)) && chunkArrayInGroups(arr.slice(size), size);

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

Browser information:

Your Browser User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36.

Link to the challenge:

That global variable is not getting reset to a blank array each time your function is ran with a specific FCC test. You can see that if you put the following console.log statement as the first line of your function:


The first time it runs, it will be a blank array, but the second time it runs, it will be what ever it returned from the last test. So, that array will keep getting bigger each after each test. You will have to rethink your logic here.