Skip to content

Commit bddc0bb

Browse files
wrote test then function and checked
1 parent e3943d2 commit bddc0bb

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

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

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

513
module.exports = countChar;

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,38 @@ 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 multiple occurrences of a character", () => {
27+
const str = "blind";
28+
const char = "a";
29+
const count = countChar(str, char);
30+
expect(count).toEqual(0);
31+
});
32+
33+
test("should count multiple occurrences of a character", () => {
34+
const str = "blood";
35+
const char = "o";
36+
const count = countChar(str, char);
37+
expect(count).toEqual(2);
38+
});
39+
40+
test("should count multiple occurrences of a character", () => {
41+
const str = "blood";
42+
const char = "l";
43+
const count = countChar(str, char);
44+
expect(count).toEqual(1);
45+
});
46+
47+
test("should count multiple occurrences of a character", () => {
48+
const str = "bbbrf";
49+
const char = "b";
50+
const count = countChar(str, char);
51+
expect(count).toEqual(3);
52+
});
53+
54+
test("should count multiple occurrences of a character", () => {
55+
const str = "ooooa";
56+
const char = "o";
57+
const count = countChar(str, char);
58+
expect(count).toEqual(4);
59+
});

0 commit comments

Comments
 (0)