Skip to content

Commit 64794e8

Browse files
committed
Solved task Sprint-3/2-practice-tdd/count.js and test cases
1 parent aa82bda commit 64794e8

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
2+
const arrToStr = stringOfCharacters.split("");
3+
4+
const countCharInArr = arrToStr.filter((char) => char === findCharacter);
5+
6+
return countCharInArr.length;
37
}
48

59
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
@@ -22,3 +22,9 @@ test("should count multiple occurrences of a character", () => {
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 return 0 if there's no occurrences of the char were found in the case-sensitive str", () => {
26+
const str = "aaaaABcGRja";
27+
const char = "b";
28+
const count = countChar(str, char);
29+
expect(count).toEqual(0);
30+
});

0 commit comments

Comments
 (0)