3 ms·
> You can make either function take arbitrarily long by increasing the size of the input. The second one scales worse. I think this is the point, the second on
by JoeBot3000 5y ago
> You can make either function take arbitrarily long by increasing the size of the input. The second one scales worse.
I think this is the point, the second one scales worse - absolutely (ignoring the bug you mentioned) however it really is more readable, and because V8 is so fast, why not use the second version?
Block comments and function names are important, but if someone needs to modify the code to add or change functionality nothing beats simple & readable code.
- recursive 5y agoYou can use .reduce((acc, curr) => curr > 0 && curr < acc ? curr : acc) and have the best of both worlds. In some cases, there are persuasive arguments to favor readability over performance, but I don't find this particular example very convincing.