Skip to content

Commit fdb496b

Browse files
feat: implement countChar with tests
1 parent dc065a9 commit fdb496b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
1+
function countChar(str, char) {
2+
let count = 0;
3+
for (let i = 0; i < str.length; i++)
4+
if(str[i] === char)
5+
{
6+
count++;
7+
}
8+
return count;
39
}
410

11+
512
module.exports = countChar;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ test("should count multiple occurrences of a character", () => {
1616
const count = countChar(str, char);
1717
expect(count).toEqual(5);
1818
});
19+
test("should count no occurrences of a character",()=>{
20+
const str = "hello";
21+
const char = "a";
22+
const count = countChar(str, char);
23+
expect(count).toEqual(0);
24+
});
1925

2026
// Scenario: No Occurrences
2127
// Given the input string `str`,

0 commit comments

Comments
 (0)