3 ms·
Thanks for checking it out! I am wondering how big is the number you are putting in? If the number is really high, it's probably causing a stack overflow. I wou
by davidim 8y ago
Thanks for checking it out! I am wondering how big is the number you are putting in? If the number is really high, it's probably causing a stack overflow. I would limit the size, but each browser has its own recursion limits so that would be quite a pain. In retrospect, I probably should not have used a recursive algorithm for this task :).
- oneeyedpigeon 8y agoI put in a value of 500, and while it didn't freeze completely, it really struggled to respond.
- davidim 8y agoRecursive division may be elegant, but it seems that may also have its disadvantages.
- wakamoleguy 8y agoOne trick you could use is to add a setTimeout or asnyc/await somewhere during the recursion. By forcing a step to be asynchronous, the stack count will be reset.