Function find

  • Remarks

    Returns undefined if no element satisfies condition.

    Example

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

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

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

        • arr: readonly T[]

        Returns undefined | T