Function satisfies

  • Returns true if the array element at index exists and satisfies condition. Negative indices count backwards from the end of the array.

    Remarks

    This function is designed to improve developer experience by eliminating the need to account for the undefined type when accessing an array element.

    Example

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

    const indexTwoPositive = A.satisfies(3, N.isPositive);
    indexTwoPositive([1, -2, 3, -4]); // true
    indexTwoPositive([-1, 2, -3, 4]); // false
    indexTwoPositive([1, 2]); // false

    const lastPositive = A.satisfies(-1, N.isPositive);
    lastPositive([1, -2, 3]); // true

    Type Parameters

    • T

    Parameters

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

          • x: T

          Returns boolean

    Returns ((arr: readonly T[]) => boolean)

      • (arr: readonly T[]): boolean
      • Parameters

        • arr: readonly T[]

        Returns boolean