Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Sprint-3/2-practice-tdd/count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
//count the occurrences of the char in the string
// Make it case insensitive
let countChar = 0;
for (const char of stringOfCharacters) {
if (char.toLowerCase() === findCharacter.toLowerCase()) {
countChar++;
}
}
return countChar;
}

module.exports = countChar;
35 changes: 35 additions & 0 deletions Sprint-3/2-practice-tdd/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,38 @@ test("should count multiple occurrences of a character", () => {
// And a character `char` that does not exist within `str`.
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of `char` were found.

test("should return 0 if the character in not in the given string", () => {
const str = "aaaaa";
const char = "b";
const count = countChar(str, char);
expect(count).toEqual(0);
});

test("should return 1 if the is 1 occurrence of the char in the string", () => {
const str = "abc";
const char = "c";
const count = countChar(str, char);
expect(count).toEqual(1);
});

test("should return 0 if there is a empty string ", () => {
const str = "";
const char = "c";
const count = countChar(str, char);
expect(count).toEqual(0);
});

test("should return 0 if character is empty", () => {
const str = "abcdefg";
const char = "";
const count = countChar(str, char);
expect(count).toEqual(0);
});

test("should be case insensitive ", () => {
const str = "Successful";
const char = "s";
const count = countChar(str, char);
expect(count).toEqual(3);
});
Loading