Function minmax

  • Find the minimum and maximum values in an iterable.

    Type Parameters

    • T


    • object: Iterable<T>

      The iterable object to search.

    • fn: ((first, second) => number)

      The 3-way comparison function to apply to the values. It should return < 0 if the first value is less than the second. 0 if the values are equivalent, or > 0 if the first value is greater than the second.

        • (first, second): number
        • Parameters

          • first: T
          • second: T

          Returns number

    Returns [T, T] | undefined

    A 2-tuple of the [min, max] values in the iterable. If multiple values are equivalent, the left-most values are returned. If the iterable is empty, this returns undefined.




    import { minmax } from '@lumino/algorithm';

    function numberCmp(a: number, b: number): number {
    return a - b;

    minmax([7, 4, 0, 3, 9, 4], numberCmp); // [0, 9]