2 ms·
In case anyone wonders about that reverse-for loop in updateCircles(): Iterating over an array in reverse allows you to remove items in the same iteration (at
by ahoge 12y ago
In case anyone wonders about that reverse-for loop in updateCircles():
Iterating over an array in reverse allows you to remove items in the same iteration (at the very end of the loop). If you delete an item, the items which follow are downshifted by one which means that their indices also change.
However, this isn't a problem if you iterate in reverse, because you already took care of those items in previous iterations. The item you'll handle next will stay where it is.
This also works nice with unordered lists (or "bags").