Created
January 14, 2016 08:20
-
-
Save TimBlock/5981a76396e07f22a991 to your computer and use it in GitHub Desktop.
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 countBs(word){ | |
| var sum=0; | |
| for( var i = 0; i < word.length; i++){ | |
| if (word.charAt(i)==="B") sum++; | |
| }; | |
| console.log(sum); | |
| }; | |
| function countChar(word, index){ | |
| var sum=0; | |
| for( var i = 0; i < word.length; i++){ | |
| if (word.charAt(i)===index) sum++; | |
| }; | |
| console.log(sum); | |
| }; | |
| console.log(countBs("BBC")); | |
| // 2 | |
| console.log(countChar("kakkerlak", "k")); | |
| // → 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment