Basic Algorithm Scripting - Chunky Monkey

Tell us what’s happening:
the code is running perfectly so far, but whenever i set size to 8, it doesnt push the last element in the arr to x. how do i get it to complete the code

  **Your code so far**
function chunkArrayInGroups(arr, size) {
let x=[]
for(let i=0; i<arr.length+2; i++){
  x.push(arr.splice(0,size))
  

}
return x;
}

console.log(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2));
  **Your browser information:**

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

Challenge: Basic Algorithm Scripting - Chunky Monkey

Link to the challenge:

stop changing the array in the loop, that’s really bad practice and gives unexpected behaviour

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.