• Remove the first occurrence of a value which matches a predicate.

    Type Parameters

    • T

    Parameters

    • array: T[]

      The array of interest.

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

      The predicate function to apply to the values.

        • (value, index): boolean
        • Parameters

          • value: T
          • index: number

          Returns boolean

    • 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 {
        index: number;
        value: T | undefined;
    }

    The removed { index, value }, which will be -1 and undefined if the value is not contained in the array.

    Notes

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

    Complexity

    Linear.

    Example

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

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

    let data = [0, 12, 23, 39, 14, 12, 75];
    ArrayExt.removeFirstWhere(data, isEven); // { index: 0, value: 0 }
    ArrayExt.removeFirstWhere(data, isEven, 2); // { index: 3, value: 14 }
    ArrayExt.removeFirstWhere(data, isEven, 4); // { index: -1, value: undefined }
    • index: number
    • value: T | undefined