Skip to content

Instantly share code, notes, and snippets.

@egermano
Created September 11, 2012 14:59
Show Gist options
  • Save egermano/3699447 to your computer and use it in GitHub Desktop.
Save egermano/3699447 to your computer and use it in GitHub Desktop.
Linear search
function linearSearch(values, target) {
for(var i = 0; i < values.length; ++i){
if (values[i] == target) { return i; }
}
return -1;
}
var result = linearSearch([7, 3, 6, 1, 0], 6);
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment