File tree Expand file tree Collapse file tree 4 files changed +4445
-3
lines changed Expand file tree Collapse file tree 4 files changed +4445
-3
lines changed Original file line number Diff line number Diff line change 11function countChar ( stringOfCharacters , findCharacter ) {
2- return 5
2+ let pattern = new RegExp ( findCharacter , "g" ) ;
3+
4+ let matchingChars = stringOfCharacters . match ( pattern ) ;
5+
6+ if ( matchingChars === null ) {
7+ return 0 ;
8+ }
9+
10+ return matchingChars . length ;
311}
412
513module . exports = countChar ;
Original file line number Diff line number Diff line change @@ -12,13 +12,19 @@ const countChar = require("./count");
1212
1313test ( "should count multiple occurrences of a character" , ( ) => {
1414 const str = "aaaaa" ;
15- const char = "a " ;
15+ const char = "b " ;
1616 const count = countChar ( str , char ) ;
17- expect ( count ) . toEqual ( 5 ) ;
17+ expect ( count ) . toEqual ( 3 ) ;
1818} ) ;
1919
2020// Scenario: No Occurrences
2121// Given the input string str,
2222// And a character char that does not exist within the case-sensitive str,
2323// When the function is called with these inputs,
2424// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.
25+ test ( "should check for no occurrences of a character" , ( ) => {
26+ const str = "abcdef" ;
27+ const char = "g" ;
28+ const count = countChar ( str , char ) ;
29+ expect ( count ) . toEqual ( 0 ) ;
30+ } ) ;
You can’t perform that action at this time.
0 commit comments