Help figuring out infiinite loop? (probably easy fix)

Hi, I’m doing chunky monkey.
“Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array.”

function chunkArrayInGroups(arr, size) {
var a = arr;
var b = [];
for ( var i = arr.length; i > 0; i - size) {
b.push(a.splice(-size));

}

return b.pop();

}

I know there’s an infinite loop, I believe it has something to do with (i - size), but I can’t figure it out…
If anyone could help, it would be very appreciated, thanks.

Also, when I relocate “return b.pop()” above the curly braces, it sends out half of what i want, but won’t do the rest?

  1. I’m not sure you need pop() in this case. Just return b.
  2. But the real issue is in your repeat assignment. By changing it to i-=size you actually assign the number to i. So, it should be more like var i = arr.length; i > 0; i - size
  3. Finally, look at splice() again. You’re pulling things off the tail of your array instead of the front.

Fix number 2, and have a second look at 1 and 3. I think you’re almost there. :slight_smile:

Thank you, that splice comment will help alot in the future lol. Got it figured out.