Skip to content

Instantly share code, notes, and snippets.

@connor11528
Created December 22, 2017 23:20
Show Gist options
  • Save connor11528/a458c6ead272c0947f56f5f59b7e9e34 to your computer and use it in GitHub Desktop.
Save connor11528/a458c6ead272c0947f56f5f59b7e9e34 to your computer and use it in GitHub Desktop.
The linear search algorithm implemented in Javascript
function linearSearch(array, toFind){
for(let i = 0; i < array.length; i++){
if(array[i] === toFind) return i;
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment