Function findIndex

  • Remarks

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

    Example

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

    const firstPositiveIndex = A.findIndex(N.isPositive);
    firstPositiveIndex([-3, -4, -1, 4, -5, 2]); // 3
    firstPositiveIndex([-3, -4, -1, -4, -5, -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