Skip to content

Instantly share code, notes, and snippets.

@tyler-austin
Created March 25, 2019 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyler-austin/78ac80988f833a2a71aadc08b9eaaf48 to your computer and use it in GitHub Desktop.
Save tyler-austin/78ac80988f833a2a71aadc08b9eaaf48 to your computer and use it in GitHub Desktop.
[JavaScript] Number of Occurances of a Character in a String
const numberOfCharInString = (c, s) => {
let [count, index] = [0, 0];
while (true) {
index = s.indexOf(c, index);
if (index >= 0) {
++count;
++index;
} else break;
}
return count;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment