You should be correct, this is O(2n). This solution should be perfectly acceptable and scale just fine with large lists. There is no need to optimize unless the code is causing actual performance issues. Readability and intent should be king unless you are seeing some issues with the code. Even running this with 6x CPU throttling, the duration for filter-then-reduce is 0.6ms for me on an array with 10000 elements. (Base CPU Ryzen 5 3600X, throttled 6x using Chrome dev tools) Unless this is being run extremely frequently or on extraordinarily large lists, it should not be a noticeable problem.
The ternary expression evaluates whether the argument
bool
is true or false, returning "Yes" if the former and "No" if the latter.Why does this work?
This comment is hidden because it contains spoiler information about the solution
ternary
Because in JS, sort doesn't work the way it works in other languages.
why does sort doesnot work!!
yes thanks for reminding me of .slice
thank you
'alr approved some time ago'
You should be correct, this is O(2n). This solution should be perfectly acceptable and scale just fine with large lists. There is no need to optimize unless the code is causing actual performance issues. Readability and intent should be king unless you are seeing some issues with the code. Even running this with 6x CPU throttling, the duration for filter-then-reduce is 0.6ms for me on an array with 10000 elements. (Base CPU Ryzen 5 3600X, throttled 6x using Chrome dev tools) Unless this is being run extremely frequently or on extraordinarily large lists, it should not be a noticeable problem.
I did it at the same way. Nice job.
yo shoes are mega raggidy
It still works, why do you say so?
Its doesn't work anymore... i have no idea how to solve it xd
это как к линтеру привыкнешь)
скобки в return не обязательны
Loading more items...