File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed
Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change 11function countChar ( stringOfCharacters , findCharacter ) {
2- return 5
2+ if (
3+ typeof stringOfCharacters != "string" ||
4+ typeof findCharacter != "string"
5+ ) {
6+ throw new Error ( "Please enter a valid string" ) ;
7+ }
8+
9+ if ( findCharacter . length != 1 ) {
10+ throw new Error (
11+ "Please enter a single character for findCharacter, e.g. 't"
12+ ) ;
13+ }
14+
15+ if ( stringOfCharacters . length === 0 ) {
16+ throw new Error (
17+ "Please enter a non-empty string, e.g. 'A series of unfortunate events'"
18+ ) ;
19+ }
20+
21+ let charCount = 0 ;
22+ let lowerCaseChar = findCharacter . toLowerCase ( ) ;
23+ for ( char of stringOfCharacters . toLowerCase ( ) ) {
24+ if ( lowerCaseChar === char ) charCount ++ ;
25+ }
26+
27+ return charCount ;
328}
429
530module . exports = countChar ;
You can’t perform that action at this time.
0 commit comments