3 ms·
Was also common in javascript a few years ago when the runtimes were more simplistic than they are now. Iterating from the tail also made the terminal conditio
by masklinn 7y ago
Was also common in javascript a few years ago when the runtimes were more simplistic than they are now.
Iterating from the tail also made the terminal condition a comparison to 0, which IIRC was faster in at least one browser.
The gains were mostly masturbatory of course, the overhead of the iteration loop is not going to matter much when you have 5 method calls in the body.
- Sahhaese 7y agoIterating from the tail has other advantages, such as if you want to remove items from the list. With negative iteration you don't need to do any special handling. But that is an optimisation for development time rather than run-time, I'd imagine multiple in-place removals is not so efficient.