Created
August 28, 2018 18:05
-
-
Save oliverbth05/ba13bd7bcdf2f2e2eb3df0d797e47a9e to your computer and use it in GitHub Desktop.
Find Substring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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