the first value found or undefined
Find the first element that is greater than 2 and return its square.
import { CONTINUE, findValue } from "@trashpanda001/helpers/array"
findValue([2, 3, 4], (x) => x > 2 ? x * x : CONTINUE)
// 9 -- found 3, result of 3 * 3
[2, 3, 4].find((x) => x > 2)
// 3 -- found 3, result of 3
[2, 3, 4].findIndex((x) => x > 2)
// 1 -- found 3, index of 1
Like
find
, but returns the value of the function invocation instead of the element itself.The return value is considered to be found if
fn
returns a value other thanCONTINUE
.