Ad
  • Custom User Avatar

    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.

  • Custom User Avatar

    I'm sorry for inflicting this on the world.