Skip to content

Commit e75c3f6

Browse files
committed
count.js + tests completed
1 parent 29ef74a commit e75c3f6

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎practice-tdd/count.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
export function countChar(stringOfCharacters, findCharacter) {
2-
return 5
2+
let count = 0;
3+
for (let i = 0; i < stringOfCharacters.length; i++) {
4+
if (stringOfCharacters[i] === findCharacter) {
5+
count = count + 1;
6+
}
7+
}
8+
return count;
39
}
10+
//1st test passsed

‎practice-tdd/count.test.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ 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+
test("A character that does not exist in the string should return 0.", () => {
26+
const str = "aaaaa";
27+
const char = "p";
28+
expect(countChar(str, char)).toEqual(0);
29+
});

0 commit comments

Comments
 (0)