Skip to content

Instantly share code, notes, and snippets.

@OneCent01
Created October 24, 2017 19:50
Show Gist options
  • Save OneCent01/dcaef986f426b333d6e49162f1938c2f to your computer and use it in GitHub Desktop.
Save OneCent01/dcaef986f426b333d6e49162f1938c2f to your computer and use it in GitHub Desktop.
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