Skip to content

Instantly share code, notes, and snippets.

@pinkmomo027
Created June 21, 2018 23:58
Show Gist options
  • Save pinkmomo027/ce439a7b37187533a6598f47c204aaba to your computer and use it in GitHub Desktop.
Save pinkmomo027/ce439a7b37187533a6598f47c204aaba to your computer and use it in GitHub Desktop.
needle and haysack
function indexOf(string, query) {
for (let i = 0; i < string.length; i++) {
//str.charAt(i)
for (let q = 0; q < query.length; q++) {
if (string[i+q] != query[q]) {
break;
}
if (q === query.length - 1) {
console.log("Found ", i);
return i;
}
}
}
return -1;
}
indexOf(str, query);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment