-
-
Save Nilesh-Saini-09/c0de3318b2314c2945a804993e5c4c36 to your computer and use it in GitHub Desktop.
Linear Search
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
// ES6 Arrow Function | |
const search = (arr, x) => { | |
for(let i = 0; i < arr.length; i++) { | |
if(arr[i] === x) return i; | |
} | |
return -1; | |
} | |
// const testArray = [2, 8, 1, 3, 6, 7, 5, 4]; | |
// let x = 6 | |
// search(testArray, x) | |
// output => 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment