Re:Why do arrays start at 0?
by 10000truths on Wednesday August 24, 2022 @02:23PM
(#32583653)
EDIT: change i to j
[ Parent
| on HN ]
That's quite broken (you'd want a different variable inside the body, vs clobbering the iteration counter, else this would process the last item in your list, then exit).
Re:Why do arrays start at 0?
by rabbidruster on Wednesday August 24, 2022 @02:32PM
(#32583788)
I hope you haven't done this anywhere.
Makes my brain hurt, but I think this will only run through the loop one time looking at the last element of the array.
Uh no don't reassign the loop variable in the inner scope. Use:
const j = (length - 1) - i;
in that case. Much safer.