UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

25 lines (23 loc) 552 B
import { dfdlT } from "@monstermann/dfdl"; //#region src/array/findLastOr.ts /** * `findLastOr(array, predicate, fallback)` * * Returns the last element in `array` that satisfies the provided `predicate` function, or `fallback` if no element is found. * * ```ts * findLastOr([1, 2, 3, 4], (x) => x > 10, 0); // 0 * ``` * * ```ts * pipe( * [1, 2, 3, 4], * findLastOr((x) => x > 10, 0), * ); // 0 * ``` */ const findLastOr = dfdlT((target, predicate, or) => { return target.findLast(predicate) ?? or; }, 3); //#endregion export { findLastOr };