Skip to content

Commit a69ca5d

Browse files
Effect Changes to the count.js and count.test.js
1 parent 3372770 commit a69ca5d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

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

513
module.exports = countChar;
14+
console.log(countChar("aaaaa", "a"));//print 5
15+
console.log(countChar("aaaaa", "z"));//print 0

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

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

0 commit comments

Comments
 (0)