Chunky monkey issue with for loop

Hi :slightly_smiling_face:, Iā€™m doing chunky monkey.: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?

First of all, be sure to precede and follow your code with three backticks (below the ESC key) so it formats nicely in the forum:

As to your code, yes, that is the cause of your infinite loop. You are never changing i. The statement i - size doesnā€™t change i. I think you want:

for ( var i = arr.length; i > 0; i -= size) {

And Iā€™m not sure about:

return b.pop();

Why are you popping? If you return b, you are a step closer.

Thank you, Iā€™ll make sure I backtick in the future. Yea, the pop is from an old version where I was going to have ā€œbā€ come equipped with a nested array, but I found out I can start an empty one.
Do you know why (i - size) wonā€™t work? Thanks for the help.

Do you know why (i - size) wonā€™t work?

Because it doesnā€™t do anything. That part of the for loop is supposed to tell what to do after each loop, usually changing your index variable. For example, usually you index i with something like i++. You are trying to subtract from i - thatā€™s fine. But you arenā€™t changing i with (i - size) it evaluates a number but doesnā€™t change i. If you want it to reduce i by size each iteration, then you have to use i-=size.

It is doneā€¦
Thanks again.