Skip to content

Instantly share code, notes, and snippets.

@chadjemmett
Created June 5, 2019 16:04
Show Gist options
  • Save chadjemmett/9575c7bc9784e75937a0ddabd051658a to your computer and use it in GitHub Desktop.
Save chadjemmett/9575c7bc9784e75937a0ddabd051658a to your computer and use it in GitHub Desktop.
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