Created
June 5, 2017 17:56
-
-
Save Dylan-Thomson/5e5be94b29a084ca6d977ac751d78464 to your computer and use it in GitHub Desktop.
CountChar - Eloquent JavaScript Chapter 3 Solution
This file contains hidden or 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 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