/array/find
stdFinds an element by a predicate function within the given array, otherwise, it returns the given fallback value or undefined when fallback is not present.
Type signature
(
predicate: (value: any, index: number, context: any[]) => boolean,
fallback?: any
) => (xs: any[]) => any
Examples
find((x) => x > 2)([1, 2, 3, 5, 7]);
// ⇒ 3
Try in REPL
find((x) => x > 2)([
1,
2,
-3,
-5,
-7,
]);
// ⇒ undefined
Try in REPL
Questions
- How to find an element of an array by a given predicate?