Last active
April 13, 2016 11:58
-
-
Save tiberiur/9630e310aaf439296900 to your computer and use it in GitHub Desktop.
[JS] Counting Occurrences of Substrings
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
function countingOccurrences(string, subString) | |
{ | |
var foundAtPosition = 0; | |
var count = 0; | |
while (foundAtPosition != -1) { | |
foundAtPosition = string.indexOf(subString, foundAtPosition); | |
if (foundAtPosition != -1) { | |
count++; | |
foundAtPosition++; | |
} | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment