ts-iterable-functions
    Preparing search index...

    Function maxByConst

    • Selects the elements whose key value is maximal according to the comparer.

      Curried version of _maxBy.

      Type Parameters

      • T

        Element type produced by the source iterable.

      • TKey

        Key type produced by the selector and consumed by the comparer.

      Parameters

      • selector: IndexedSelector<T, TKey>

        Selector receiving each element and its index, producing the key used for comparison.

      • comparer: Comparer<TKey> = defaultComparer

        Comparer determining ordering between keys; defaults to defaultComparer.

      Returns (src: Iterable) => Iterable

      An iterable containing every element sharing the maximal key, or an empty iterable when the source is empty.

      Error Rethrows any error thrown by selector or comparer.

      const players = [
      { name: "Ada", score: 18 },
      { name: "Tess", score: 24 },
      { name: "Ian", score: 24 },
      ];
      const topPlayers = [..._maxBy(players, (player) => player.score)];
      console.log(topPlayers);
      // [ { name: "Tess", score: 24 }, { name: "Ian", score: 24 } ]

      or using the curried version:

      const topPlayers = [
      ...pipeInto(
      [
      { name: "Ada", score: 18 },
      { name: "Tess", score: 24 },
      { name: "Ian", score: 24 },
      ],
      maxBy((player) => player.score)
      ),
      ];
      console.log(topPlayers);
      // [ { name: "Tess", score: 24 }, { name: "Ian", score: 24 } ]