Created
June 5, 2019 16:04
-
-
Save chadjemmett/9575c7bc9784e75937a0ddabd051658a to your computer and use it in GitHub Desktop.
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
| const stringCheck = (strBig, strSmall) => { | |
| let count = 0 | |
| const bigStrLen = strBig.length | |
| const smallStrLen = strSmall.length | |
| let tempString = "" | |
| for(let i=0; i<bigStrLen - smallStrLen + 1; i++ ) { | |
| if (strBig[i] === strSmall[0]) { | |
| tempString = strBig.slice(i, i + strSmall.length) | |
| if (tempString === strSmall) { | |
| count += 1 | |
| tempString = "" | |
| } else { | |
| tempString = "" | |
| } | |
| } | |
| // console.log(strBig.slice(i, i + strSmall.length)) | |
| } | |
| return count | |
| } | |
| console.log(stringCheck("hello world", "or")) // <= 1 | |
| console.log(stringCheck("momomomomomomomomomo", "mo")) // <= 10 | |
| console.log(stringCheck("hello world", "mo")) // <= 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment