UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

45 lines (43 loc) 1.13 kB
import { ArrayPredicate, OrElse } from "./internals/types.js"; //#region src/array/findLastIndexOrElse.d.ts /** * `findLastIndexOrElse(target, predicate, orElse)` * * Returns the index of the last element in `target` that satisfies the provided `predicate` function. If no element satisfies the predicate, calls `orElse` with the original array. * * ```ts * findLastIndexOrElse( * [1, 3, 2, 4], * (x) => x > 2, * () => -1, * ); // 3 * findLastIndexOrElse( * [1, 2, 3, 4], * (x) => x > 5, * (arr) => arr.length, * ); // 4 * ``` * * ```ts * pipe( * [1, 3, 2, 4], * findLastIndexOrElse( * (x) => x > 2, * () => -1, * ), * ); // 3 * pipe( * [1, 2, 3, 4], * findLastIndexOrElse( * (x) => x > 5, * (arr) => arr.length, * ), * ); // 4 * ``` */ declare const findLastIndexOrElse: { <T, U>(predicate: ArrayPredicate<T>, orElse: OrElse<T, U>): (target: readonly T[]) => number | U; <T, U>(target: readonly T[], predicate: ArrayPredicate<T>, orElse: OrElse<T, U>): number | U; }; //#endregion export { findLastIndexOrElse };