• Find the index of the first element which compares >= to a value.

    Type Parameters

    • T
    • U

    Parameters

    • array: ArrayLike<T>

      The sorted array-like object to search.

    • value: U

      The value to locate in the array.

    • fn: ((element, value) => number)

      The 3-way comparison function to apply to the values. It should return < 0 if an element is less than a value, 0 if an element is equal to a value, or > 0 if an element is greater than a value.

        • (element, value): number
        • Parameters

          • element: T
          • value: U

          Returns number

    • start: number = 0

      The index of the first element in the range to be searched, inclusive. The default value is 0. Negative values are taken as an offset from the end of the array.

    • stop: number = -1

      The index of the last element in the range to be searched, inclusive. The default value is -1. Negative values are taken as an offset from the end of the array.

    Returns number

    The index of the first element which compares >= to the value, or length if there is no such element. If the computed index for stop is less than start, then the computed index for start is returned.

    Notes

    The array must already be sorted in ascending order according to the comparison function.

    Complexity

    Logarithmic.

    Undefined Behavior

    Searching a range which is not sorted in ascending order.

    A start or stop which is non-integral.

    Modifying the length of the array while searching.

    Example

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

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

    let data = [0, 3, 4, 7, 7, 9];
    ArrayExt.lowerBound(data, 0, numberCmp); // 0
    ArrayExt.lowerBound(data, 6, numberCmp); // 3
    ArrayExt.lowerBound(data, 7, numberCmp); // 3
    ArrayExt.lowerBound(data, -1, numberCmp); // 0
    ArrayExt.lowerBound(data, 10, numberCmp); // 6