Skip to content

Commit 0dfaf80

Browse files
committed
get count test file update
1 parent 610f195 commit 0dfaf80

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
2+
let count = 0;
3+
4+
for (let char of stringOfCharacters) {
5+
if (char === findCharacter) {
6+
count++;
7+
}
8+
}
9+
return count;
310
}
411

512
module.exports = countChar;

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

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

20-
// Scenario: No Occurrences
20+
//Scenario: No Occurrences
21+
test("should return 0 when the character does not exist in the string", () => {
22+
const str = "hello";
23+
const char = "z";
24+
const count = countChar(str, char);
25+
expect(count).toEqual(0);
26+
});
27+
2128
// Given the input string `str`,
2229
// And a character `char` that does not exist within `str`.
2330
// When the function is called with these inputs,

0 commit comments

Comments
 (0)