Comment

Comment by RomanKornev

Every single `reduce` can be replaced with a more intuitive `groupBy`, `partition`, `mapValues`, `keyBy`, etc.

Reduce can approximate anything, that doesn't mean we should use it.

My favorite antipattern is

  items.reduce(
    (acc, item) => ({
      ...acc,
      [item.id]: item,
    }), {}
  );
Like, why? Not only is this ridiculously inefficient O(N^2), it's also longer and less understandable than "build a new map" version.
parent RomanKornev 1 month ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton