Skip to content

Instantly share code, notes, and snippets.

@Nilesh-Saini-09
Created June 19, 2022 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nilesh-Saini-09/c0de3318b2314c2945a804993e5c4c36 to your computer and use it in GitHub Desktop.
Save Nilesh-Saini-09/c0de3318b2314c2945a804993e5c4c36 to your computer and use it in GitHub Desktop.
Linear Search
// 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