Skip to content

Commit 15f6b6b

Browse files
committed
Implement countChar function and tests
1 parent ea0fca9 commit 15f6b6b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Sprint-3/2-practice-tdd/count.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
2+
let counter = 0 ;
3+
for (let i=0 ;i< stringOfCharacters.length ; i++){
4+
if (stringOfCharacters.charAt(i)==findCharacter){
5+
counter ++;
6+
7+
}
8+
9+
}
10+
return counter;
311
}
12+
console.log(countChar("aaa","a"));
13+
console.log(countChar("aaba","b"));
414

515
module.exports = countChar;
16+

Sprint-3/2-practice-tdd/count.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,22 @@ test("should count multiple occurrences of a character", () => {
1717
expect(count).toEqual(5);
1818
});
1919

20+
test("should count multiple occurrences of a character", () => {
21+
const str = "aaaa";
22+
const char = "a";
23+
const count = countChar(str, char);
24+
expect(count).toEqual(4);
25+
});
26+
2027
// Scenario: No Occurrences
2128
// Given the input string str,
2229
// And a character char that does not exist within the case-sensitive str,
2330
// When the function is called with these inputs,
2431
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.
32+
test("should count multiple No occurrences of a character", () => {
33+
const str = "aaaa";
34+
const char = "b";
35+
const count = countChar(str, char);
36+
expect(count).toEqual(0);
37+
});
38+

0 commit comments

Comments
 (0)