Function sliceSatisfies

  • Returns true if each element from the slice beginning at startIndex and continuing with as many elements as there are in conditions exist and pass their corresponding conditions. In other words, the first element in the slice passes the first condition, the next element passes the second condition, etc.

    Negative startIndex values count backwards from the end of the array.

    Example


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

    const posNegPos = A.sliceSatisfies(1, [N.isPositive, N.isNegative, N.isPositive]);
    posNegPos([0, 2, -2, 2, 0, 0]); // true
    posNegPos([0, 2, -2, -2, 0, 0]); // false
    posNegPos([2, -2, 2, 0, 0]); // false

    const endsNineTen = A.sliceSatisfies(-2, [L.equals(9), L.equals(10)]);
    endsNineTen([5, 9, 10]); // true
    endsNineTen([9, 10, 5]); // false
    endsNineTen([9]); // false

    Type Parameters

    • T

    Parameters

    • startIndex: number
    • conditions: ((x: T) => boolean)[]

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

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

        • arr: readonly T[]

        Returns boolean