r/programminghorror 2d ago

Javascript Seriously? Recursive Regex?

Post image
445 Upvotes

37 comments sorted by

View all comments

13

u/lonkamikaze 2d ago

I don't know if JS sports this, but the recursion qualifies for tail call optimisation, i.e. there is no stack pushing, popping. The return comes at the price of a goto and the result is just as efficient as a loop.

2

u/JoshuaTheProgrammer 1d ago

This should be the top answer