Created
July 10, 2022 17:25
-
-
Save helabenkhalfallah/7bbb5bf51bcb79ee60b0708b4ed5ae7f to your computer and use it in GitHub Desktop.
Vintage Linear Search
This file contains hidden or 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
const vintageLinearSearch = (data, target) => { | |
for (let i in data) { | |
if (data[i] === target) return i | |
} | |
return -1 | |
} | |
console.log(vintageLinearSearch([1, 2, 3, 4], 1)) // 0 | |
console.log(vintageLinearSearch([1, 2, 3, 4], 4)) // 3 | |
console.log(vintageLinearSearch([1, 2, 3, 4], 6)) // -1 | |
console.log(vintageLinearSearch([3, 4, 1, 6, 3], 6)) // 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment