Skip to content

Instantly share code, notes, and snippets.

@jg75
Created June 26, 2018 20:39
Show Gist options
  • Save jg75/83b932afa9ca7707fae4188af5dbd410 to your computer and use it in GitHub Desktop.
Save jg75/83b932afa9ca7707fae4188af5dbd410 to your computer and use it in GitHub Desktop.
another typescript example
function search(text:string, pattern:string): number {
let i:number = 0
let j:number = 0
for (i = 0; i < text.length; i++) {
for (j = 0; j < pattern.length && i + j < text.length; j++) {
if (text.charAt(i + j) != pattern.charAt(j)) {
break
}
}
if (j == pattern.length) {
return i
}
}
return -1
}
console.log(search("ababacaba", "abac"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment