Skip to content

Instantly share code, notes, and snippets.

@s-amemiya
Created May 9, 2018 06:43
Show Gist options
  • Save s-amemiya/60c49981ed17327dda873b8cf54a8097 to your computer and use it in GitHub Desktop.
Save s-amemiya/60c49981ed17327dda873b8cf54a8097 to your computer and use it in GitHub Desktop.
const search = (array, target) => {
for (var i = 0; i < array.length; ++i) {
if (array[i] == target) { return i }
}
return -1
}
var numbers = [ 1, 3, 6, 13, 21 ]
console.log(search(numbers, 13)) // 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment