Function findLastIndex

  • Remarks

    Returns undefined if no element satisfies condition. This differs from the built-in Array.findLastIndex(), but is more consistent with other functions in this library.

    Example

    import * as A from "flurp/array";
    import * as N from "flurp/number";

    const lastPositiveIndex = A.findLastIndex(N.isPositive);
    lastPositiveIndex([-3, -4, 1, -5, 8, -2]); // 4
    lastPositiveIndex([-3, -4, -1, -5, -8, -2]); // undefined

    Type Parameters

    • T

    Parameters

    • condition: ((x: T) => boolean)
        • (x: T): boolean
        • Parameters

          • x: T

          Returns boolean

    Returns ((arr: readonly T[]) => undefined | number)

      • (arr: readonly T[]): undefined | number
      • Parameters

        • arr: readonly T[]

        Returns undefined | number