Function findLast

Finds the last element in the source array that satisfies the provided predicate function.

Returns undefined if no element satisfies the predicate.

const findLastPositive = findLast((x: number) => x > 0);
const a = findLastPositive([1, 2, 3]); // 3
const b = findLastPositive([-1, 0, -2]); // undefined
  • Type Parameters

    • Item

    Parameters

    • predicate: ((item: Item) => boolean)
        • (item): boolean
        • Parameters

          Returns boolean

    Returns ((source: readonly Item[]) => undefined | Item)

      • (source): undefined | Item
      • Parameters

        • source: readonly Item[]

        Returns undefined | Item