Skip to content

Commit 1cc87c5

Browse files
committed
complete 2-practice-tdd/count task
1 parent 3372770 commit 1cc87c5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-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 charRegex = new RegExp(findCharacter, "g");
3+
console.log(charRegex, typeof charRegex, "regex");
4+
const charArr = [...stringOfCharacters.matchAll(charRegex)];
5+
console.log(charArr, "array");
6+
return charArr.length;
37
}
48

59
module.exports = countChar;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ test("should count multiple occurrences of a character", () => {
2222
// And a character `char` that does not exist within `str`.
2323
// When the function is called with these inputs,
2424
// Then it should return 0, indicating that no occurrences of `char` were found.
25+
26+
test("should count 0 occurrences of a character", () => {
27+
const str = "dog";
28+
const char = "a";
29+
const count = countChar(str, char);
30+
expect(count).toEqual(0);
31+
});

0 commit comments

Comments
 (0)