I’m stumped. Below is my code, but it says that there is an infinite loop in line 5. Can someone sort of walk me through this / provide and help or feedback?
Thanks!
function chunkArrayInGroups(arr, size) {
// Break it up.
var ans = [];
for (i=0;i<arr.length;i+size) {
ans.push(arr.slice(i,size));
}
return ans;
}
You do this - arr.slice(i,size). Here i is changing at each iteration and size does not. But if you read about the slice method - you’ll see how it’s written arr.slice([begin[, end]]). So, in your case begin point is changing, but end point is always the same…
aha!! Thanks so much! Got it all figured out now! I wasn’t fully udnerstanding how slice works… I thought the end variable is how many places to the right from the start variable the end is, but its a static place. Thanks so much for your help