• Category

    Returns the value of the first element in the iterable where predicate is truthy, and undefined otherwise.

    Time complexity: O(n)

    Space complexity: O(1)

    Type Parameters

    • T

    Parameters

    • iterable: Iterable<T>

      The iterable to take elements from

    • predicate: ((element: T) => boolean)

      The function to call on each element in the iterable to determine if it passes the test

        • (element): boolean
        • Parameters

          • element: T

          Returns boolean

    Returns T | undefined

    The value of the first element in the iterable where predicate is truthy, and undefined otherwise

    Iterable

    find([1, 2, 3], x => x === 2); // 2