javascript-collections-framework
    Preparing search index...

    Function max

    • Returns the greatest element of elements by comparator (natural order when omitted), the first one found among equals, or undefined when there is none. A single element is returned without a comparison.

      Time: O(n), exactly n − 1 comparator calls.

      Type Parameters

      • E

      Parameters

      • elements: Iterable<E>

        Any iterable.

      • Optionalcomparator: Comparator<E>

        The order; natural order when omitted.

      Returns E | undefined

      The greatest element, or undefined.

      TypeError when elements is not iterable, comparator is not a function, or it returns a non-number or NaN.

      NullElementError when natural order meets null or undefined.

      ClassCastError when natural order meets values of different kinds.

      max(['pear', 'apple'], (a, b) => a.length - b.length) // 'apple'