Skip to content

Instantly share code, notes, and snippets.

@Dylan-Thomson
Created June 5, 2017 17:56
Show Gist options
  • Select an option

  • Save Dylan-Thomson/5e5be94b29a084ca6d977ac751d78464 to your computer and use it in GitHub Desktop.

Select an option

Save Dylan-Thomson/5e5be94b29a084ca6d977ac751d78464 to your computer and use it in GitHub Desktop.
CountChar - Eloquent JavaScript Chapter 3 Solution
function countChar(str, char) {
var count = 0;
for(var i = 0; i < str.length; i++) {
if(str.charAt(i) === char) count++;
}
return count;
}
function countBs(str) {
return countChar(str, "B");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment