28 Apr 2023

Use findIndex to Implement Find

Taken from Execute Program

Use .findIndex to write the function find(arr, callback). It should return the first element where callback(element) is true. If the element is not found, it should return undefined.


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


Solution tested in REPL:


Webmentions & Comments

Copyright © Paramdeo Singh · Built with Jekyll in 🇬🇾 · All Rights Reserved

[ this node is permanently morphing last updated on 28 May 2023 ]

Paramdeo Singh Guyana

Generalist. Edgerunner. Riding the wave of consciousness in this treacherous mortal sea.

Technology Design Strategy Literature Personal Blogs
Search Site

Results are from Blog, Link Dumps, and #99Problems