Implement the Chunky Monkey Algorithm - Implement the Chunky Monkey Algorithm

Tell us what’s happening:

I don’t understand why it doesn’t pass the test. I do see that at the begining and end of the array is a space that should’t be but I don’t understant why it is and how to correct that ! Thanks for your time.

Your code so far

let newArray = [];
let arrayHold = [];
function chunkArrayInGroups(arr, num){

  outloop: for(let i = 0; i<=arr.length; i += num){
    newArray = arr.slice(i, i+num);
    if(newArray == ""){
      break;
    }
    arrayHold.push(newArray);
  }
  return arrayHold;
}

let array = [0, 1, 2, 3, 4, 5, 6, 7, 8];
let num = 2;


chunkArrayInGroups(array, num);
console.log(arrayHold);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0

Challenge Information:

Implement the Chunky Monkey Algorithm - Implement the Chunky Monkey Algorithm

why are you using these global variables?

what happens if you call the function twice in a row?
like this

chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2);
chunkArrayInGroups(["a", "b", "c", "d"], 2)

Thank you so much ! I’ve grasped the function call and variable assignement better :smiley: