Skip to content

Instantly share code, notes, and snippets.

@oliverbth05
Created August 28, 2018 18:05
Show Gist options
  • Save oliverbth05/ba13bd7bcdf2f2e2eb3df0d797e47a9e to your computer and use it in GitHub Desktop.
Save oliverbth05/ba13bd7bcdf2f2e2eb3df0d797e47a9e to your computer and use it in GitHub Desktop.
Find Substring
function subStr(str, sub) {
let i = 0;
let j = 0;
let collected = '';
let counter = 0;
let complete = false;
while (complete === false) {
if(str[i] === sub[j]) {
collected += str[i]
j++
i++
if(collected === sub) {
counter ++;
collected = '';
j = 0;
}
}
else {
collected = '';
j = 0;
i ++
}
if(i === str.length) {
complete = true
}
}
return counter
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment