Returns the first slice of the array (starting with slice(0, 0), then slice(0, 1), etc.) which passes condition. Returns undefined if no slice of the array beginning with the first element passes.
slice(0, 0)
slice(0, 1)
condition
undefined
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.findSlice(twoPositive);firstSlice([2, -4, 1, -5, 6]); // [2, -4, 1]firstSlice([2, -4]); // undefined
Returns the first slice of the array (starting with
slice(0, 0)
, thenslice(0, 1)
, etc.) which passescondition
. Returnsundefined
if no slice of the array beginning with the first element passes.Example