Chunky Monkey problem

Hi,

I’m stumped as to what the problem is with the following code. I get warnings about a potential infinite loop. Any hints?

function chunkArrayInGroups(arr, size) {
  var add = [];
  var newArr = [];
  for (var i = 0; i < arr.length; i+size) {
    if (i+size < arr.length) {
      add = arr.slice(i, i+size);
    }
    else {
      add = arr.slice(i);
    }
    newArr.push(add);
  }
  return newArr;
}

My suggestion is to look carefully at your for loop code, specifically at the final expression. Does it increment the variable i as you expect?

1 Like