• Find the index of the last value which matches a predicate.

    Type Parameters

    • T

    Parameters

    • array: ArrayLike<T>

      The array-like object to search.

    • fn: ((value, index) => boolean)

      The predicate function to apply to the values.

        • (value, index): boolean
        • Parameters

          • value: T
          • index: number

          Returns boolean

    • start: number = -1

      The index of the first 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.

    • stop: number = 0

      The index of the last 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.

    Returns number

    The index of the last matching value, or -1 if no matching value is found.

    Notes

    If start < stop the search will wrap at the front of the array.

    Complexity

    Linear.

    Undefined Behavior

    A start or stop which is non-integral.

    Modifying the length of the array while searching.

    Example

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

    function isEven(value: number): boolean {
    return value % 2 === 0;
    }

    let data = [1, 2, 3, 4, 3, 2, 1];
    ArrayExt.findLastIndex(data, isEven); // 5
    ArrayExt.findLastIndex(data, isEven, 4); // 3
    ArrayExt.findLastIndex(data, isEven, 0); // -1
    ArrayExt.findLastIndex(data, isEven, 0, 1); // 5