Skip to content

Instantly share code, notes, and snippets.

@adames
Last active July 20, 2017 04:10
Show Gist options
  • Save adames/0015de23618f6d7c939ec8f828c15d56 to your computer and use it in GitHub Desktop.
Save adames/0015de23618f6d7c939ec8f828c15d56 to your computer and use it in GitHub Desktop.
function find(array, searchCriteria) {
let current = array
let next = []
while (current) {
if (searchCriteria(current)) {
return current
}
if (Array.isArray(current)) {
for (let i = 0; i < current.length; i++) {
next.push(current[i])
}
}
current = next.shift()
}
return null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment