Created
October 24, 2017 19:50
-
-
Save OneCent01/dcaef986f426b333d6e49162f1938c2f to your computer and use it in GitHub Desktop.
This file contains 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 countSubstringOccurrances = function(string, query) { | |
let count = 0; | |
while(string.includes(query)) { | |
count++; | |
let index = string.indexOf(query); | |
string = string.slice(-(string.length-1-string.indexOf(query))); | |
} | |
return count; | |
}; | |
countSubstringOccurrances('hello therell', 'll'); // => 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment