@mirei/ts-collections
    Preparing search index...

    Function minBy

    • Returns the element whose projected key is smallest according to the provided comparator.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      • TKey

        Type of key produced by keySelector.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • keySelector: Selector<TElement, TKey>

        Selector used to project each element to the key used for comparison.

      • Optionalcomparator: OrderComparator<TKey, TKey>

        Optional order comparator used to compare keys. Defaults to the library's standard order comparison when omitted.

      Returns TElement

      The element whose key is minimal.

      Thrown when the sequence is empty.

      When multiple elements share the minimal key, the first such element in the sequence is returned.

      const people = [
      { name: 'Alice', age: 25 },
      { name: 'Bob', age: 30 },
      { name: 'Charlie', age: 22 },
      ];
      const youngestPerson = minBy(people, p => p.age);
      console.log(youngestPerson); // { name: 'Charlie', age: 22 }