Function findSliceRight

  • Returns the first slice of the array of length len from the right (starting with slice(len - 1), then slice(len - 1), etc.) which passes condition. Returns undefined if no slice of the array ending with the last element passes.

    Example

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

    const twoPositive = (arr: ReadonlyArray<number>) => A.count(N.isPositive)(arr) >= 2;
    const firstSlice = A.findSliceRight(twoPositive);
    firstSlice([2, -4, 1, -5, 6]); // [1, -5, 6]
    firstSlice([2, -4]); // undefined

    Type Parameters

    • T

    Parameters

    • condition: ((a: readonly T[]) => boolean)
        • (a: readonly T[]): boolean
        • Parameters

          • a: readonly T[]

          Returns boolean

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

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

        • arr: readonly T[]

        Returns undefined | T[]