Taken from Execute Program
Use
.findIndex
to write the functionfind(arr, callback)
. It should return the first element wherecallback(element)
istrue
. If the element is not found, it should returnundefined
.
Solution
This is the answer I came up with:
// typescript
function find(arr: Array<any>, callback: any) {
let index = arr.findIndex(callback)
return ( index >= 0 ) ? arr[index] : undefined
}