findIndexOr
ts
function Array.findIndexOr<T, U>(
target: readonly T[],
predicate: (
value: NoInfer<T>,
index: number,
target: readonly NoInfer<T>[],
) => boolean,
or: U,
): number | UReturns the index of the first element in target that satisfies the provided predicate function. If no element satisfies the predicate, returns or.
Example
ts
import { Array } from "@monstermann/array";
Array.findIndexOr([1, 2, 3, 4], (x) => x > 2, -1); // 2
Array.findIndexOr([1, 2, 3, 4], (x) => x > 5, -1); // -1ts
import { Array } from "@monstermann/array";
pipe(
[1, 2, 3, 4],
Array.findIndexOr((x) => x > 2, -1),
); // 2
pipe(
[1, 2, 3, 4],
Array.findIndexOr((x) => x > 5, -1),
); // -1