Last active
July 20, 2017 04:10
-
-
Save adames/0015de23618f6d7c939ec8f828c15d56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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