Skip to content

Commit d110d21

Browse files
committed
Complete count exercise
1 parent 8f3d6cf commit d110d21

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
2+
return stringOfCharacters.split("").reduce((accumulator, character) => {
3+
return accumulator + (character === findCharacter ? 1 : 0);
4+
}, 0);
35
}
46

57
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 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+
26+
test("should count no occurences of z characters", () => {
27+
const str = "aaaaa";
28+
const char = "z";
29+
const count = countChar(str, char);
30+
expect(count).toEqual(0);
31+
});

0 commit comments

Comments
 (0)