I don’t know if it’s too late to jump in, but I was (and maybe still am a little) struggling to understand what’s going on. So I broke it down. I’m going to pass an array directly into the function for the arr argument, and 2 for the size argument, and then I’m going to go through each return statement for chunkArrayInGroups function:
// 1st function call:
chunkArrayInGroups( [3, 4, 2, 8, 9, 10, 200 ], 2 ) );
// its return statement:
// [ [3, 4] ].concat(chunkArrayInGroups( [2, 8, 9, 10, 200], 2 ) );
// 2nd function call:
chunkArrayInGroups( [2, 8, 9, 10, 200], 2 );
// its return statement:
// [ [2, 8] ].concat( chunkArrayInGroups( [9, 10, 200], 2 ) );
// 3rd function call:
chunkArrayInGroups( [9, 10, 200], 2 );
// its return statement:
// [ [9, 10] ].concat( chunkArrayInGroups( [200], 2 ) );
// 4th function call:
chunkArrayInGroups( [200], 2 );
// since it meets the if statment's condition ( [200].length <= 2 ),
// it returns [ [200] ]
// which triggers the whole returning process:
[ [200] ] is returned which begins concatenation starting with to the 4th call of the chunkArrayInGroups function,
//which returns [ [200] ] in the 4th function call and concatenates that to [ [9, 10] ]
// which returns [ [9, 10], [200] ] in 3rd function call and concatenates that to [ [2, 8] ]
// which returns [ [2, 8], [9, 10], [200] ] in the 2nd function call and concatenates that to [ [3, 4] ]
// which returns [ [3, 4] , [2, 8], [9, 10], [200] ] in the 1st function call, finishing the recursive function.```
Writing that out helped me to see what's happening better. I hope it helps you. I hope you have a great day.