Skip to content

Commit a3b9260

Browse files
committed
completed jest testing on count test and implemented the function
1 parent b31a586 commit a3b9260

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
3-
}
2+
if(stringOfCharacters === "" || findCharacter === ""){
3+
throw new Error("string an char are not given")
4+
}
5+
6+
const str = stringOfCharacters.split("")
7+
let count = 0;
8+
for(const char of str){
9+
if(char === findCharacter){
10+
count++
11+
}
12+
}
13+
return count
414

15+
}
16+
countChar("aeioyuyuuiiiiu", "i")
517
module.exports = countChar;
18+
//push char into a new array and count the lenght on new array return the lenght

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ test("should count multiple occurrences of a character", () => {
1919

2020
// Scenario: No Occurrences
2121
// Given the input string `str`,
22+
2223
// And a character `char` that does not exist within `str`.
2324
// When the function is called with these inputs,
2425
// Then it should return 0, indicating that no occurrences of `char` were found.
26+
27+
test("should return 0 when no occurrence of the char", () => {
28+
const str = "aeiou";
29+
const char = "b";
30+
const count = countChar(str, char);
31+
expect(count).toEqual(0);
32+
})

0 commit comments

Comments
 (0)