Created
October 25, 2017 12:34
-
-
Save abdulhalim-cu/8df7aaf0df74d40e21b82a2c3121ba30 to your computer and use it in GitHub Desktop.
You can get the Nth character, or letter, from a string by writing "string".charAt(N), similar to how you get its length with "s".length. The returned value will be a string containing only one character (for example, "b"). The first character has position zero, which causes the last one to be found at position string.length - 1. In other words,…
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
| // Your code here. | |
| function countBs(string){ | |
| number_of_bs = 0; | |
| for (count = 0; count < string.length; count++){ | |
| if (string[count] == "B") | |
| number_of_bs += 1; | |
| } | |
| return number_of_bs; | |
| } | |
| function countChar(string, char){ | |
| number_of_char = 0; | |
| for (count = 0; count < string.length; count++){ | |
| if (string[count] == char) | |
| number_of_char += 1; | |
| } | |
| return number_of_char; | |
| } | |
| console.log(countBs("BBC")); | |
| // → 2 | |
| console.log(countChar("KKKKBCD", "K")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment