I think you are making a bad assumption here. Look at the last few test cases. How many elements are in the array being passed in? What happens when you divide the length of those arrays by the size?
What I was trying to get you to see is that the size does not always divide evenly into the arr.length. Look at the last test case. The length of arr is 9, so 9/2 = 4.5. Do you see why your for loop isn’t always going through the entire array?
Ahh, ya, I was focusing on the wrong thing in your original code. The splice method changes the array that you call it on. So arr.splice(0, size) removes elements from arr. So each time the for loop does i < arr.length / size the length of arr is smaller because splice removed elements from it. So your for loop is going to exit earlier than you think because i keeps growing and arr.length keeps shrinking.
Thanks, mate. That’s correct. The remaining arr keeps shrinking, but what I spliced ervey time is the remaining arr’s[0,2], so it doesn’t splice 2 elements from the remaining arr?
Add a console.log('i=', i); at the beginning of your for loop and I think you’ll see what I am talking about. Also, add a console.log('newArr=', newArr); right before the return statement. It should become clear that your for loop isn’t doing enough iterations to produce the correct results.