3 ms·
Those ones. But what I meant was that it is idiomatic to use for loops vs recursion.
by tieTYT 13y ago
Those ones. But what I meant was that it is idiomatic to use for loops vs recursion.
- michaelsbradley 13y agoThat's true, and may be reinforced somewhat by the fact that JavaScript doesn't eliminiate tail calls. In other words, there are situations where a recursive algorithm would be clean and compact, but might result in the call stack being blown inadvertently. I ran into this recently while building a "practical" monads library for JavaScript. Each monad and transformer has sync and async variants. The sync variants can't use straight recursion because "deep" monadic binds will result in a blown call stack. The solution was/is to allocate on the heap in terms of an array that acts as a manually operated call stack (I think I essentially implemented a "trampoline" but I'm not 100% certain).