From 3fbf92e0557b42b293c50352d1ac73d940cabdca Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Sat, 11 Jul 2026 16:06:27 +0100 Subject: [PATCH 1/2] Implement the function countChar Sprint-3/2-practice-tdd/count.js --- Sprint-3/2-practice-tdd/count.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..3d1adb7362 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -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; From 80396406c488907cc418d25ce84ff3c728dbe625 Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Sat, 11 Jul 2026 16:09:42 +0100 Subject: [PATCH 2/2] written tests for Sprint-3/2-practice-tdd/count.test.js --- Sprint-3/2-practice-tdd/count.test.js | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf7..22b5f4ce73 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -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); +});