From 3fbf92e0557b42b293c50352d1ac73d940cabdca Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Sat, 11 Jul 2026 16:06:27 +0100 Subject: [PATCH 1/9] 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/9] 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); +}); From 2e640383d9187b4ca1faa592a6098e53ce80366f Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Sat, 11 Jul 2026 22:12:20 +0100 Subject: [PATCH 3/9] Write tests Sprint-3/2-practice-tdd/repeat-str.test.js --- Sprint-3/2-practice-tdd/repeat-str.test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index a3fc1196c4..9df3a34b57 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -21,12 +21,30 @@ test("should repeat the string count times", () => { // When the repeatStr function is called with these inputs, // Then it should return the original `str` without repetition. +test("should repeat the string count times", () => { + const str = "hello"; + const count = 1; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("hello"); +}); + // Case: Handle count of 0: // Given a target string `str` and a `count` equal to 0, // When the repeatStr function is called with these inputs, // Then it should return an empty string. +test("should repeat the string count times", () => { + const str = "hello"; + const count = 0; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual(""); +}); // Case: Handle negative count: // Given a target string `str` and a negative integer `count`, // When the repeatStr function is called with these inputs, // Then it should throw an error, as negative counts are not valid. +test("throws an error when count is a negative value", () => { + const str = "hello"; + const count = -1; + expect(() => repeatStr(str, count)).toThrow("Count must not be negative"); +}); From 78c7248ce456bd8de83a05684016aa35a89570d9 Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Sat, 11 Jul 2026 22:14:28 +0100 Subject: [PATCH 4/9] Implemented repeatSttr(), Sprint-3/2-practice-tdd/repeat-str.js --- Sprint-3/2-practice-tdd/repeat-str.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 2af0a2cea7..08b2e7cf2e 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,7 +1,16 @@ -function repeatStr() { - // Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat). - // The goal is to re-implement that function, not to use it. - return "hellohellohello"; +// Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat). +// The goal is to re-implement that function, not to use it. + +function repeatStr(str, count) { + if (count < 0) { + throw new Error("Count must not be negative"); + } + let newString = ""; + for (let i = 0; i < count; i++) { + newString += str; + } + + return newString; } module.exports = repeatStr; From 0ea5c58e95023c14a6069ac0ada87db4b49cbd59 Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Sat, 11 Jul 2026 22:15:52 +0100 Subject: [PATCH 5/9] updated json run npm install --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0657e22dd8..5ebcdf7334 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "keywords": [], "author": "Code Your Future", "license": "ISC", - "dependencies": { - "jest": "^29.7.0" + "devDependencies": { + "jest": "^30.4.2" } -} \ No newline at end of file +} From a0ddb5acc66cf0b0962ff077ccf85157b9f2e287 Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Tue, 14 Jul 2026 17:23:14 +0100 Subject: [PATCH 6/9] Implement ordinal number function --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..0c5796f254 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,15 @@ function getOrdinalNumber(num) { - return "1st"; + let lastTwoDigits = num % 100; + let lastDigit = num % 10; + if (lastTwoDigits === 11 || lastTwoDigits === 12 || lastTwoDigits === 13) { + return num + "th"; + } else if (lastDigit === 1) { + return num + "st"; + } else if (lastDigit === 2) { + return num + "nd"; + } else if (lastDigit === 3) { + return num + "rd"; + } else return num + "th"; } module.exports = getOrdinalNumber; From 6d0ac5648084a392a195b20be8b5769371d659cc Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Tue, 14 Jul 2026 17:23:47 +0100 Subject: [PATCH 7/9] Add tests for ordinal number --- .../2-practice-tdd/get-ordinal-number.test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js index adfa58560f..d87be14498 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -14,7 +14,24 @@ const getOrdinalNumber = require("./get-ordinal-number"); // When the number ends with 1, except those ending with 11, // Then the function should return a string by appending "st" to the number. test("should append 'st' for numbers ending with 1, except those ending with 11", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); expect(getOrdinalNumber(1)).toEqual("1st"); expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); + +// Case 2: Numbers ending with 2 (but not 12) +test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(112)).toEqual("112th"); + expect(getOrdinalNumber(32)).toEqual("32nd"); + expect(getOrdinalNumber(332)).toEqual("332nd"); +}); + +// Case 3: Numbers ending with 3 (but not 13) +test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { + expect(getOrdinalNumber(13)).toEqual("13th"); + expect(getOrdinalNumber(113)).toEqual("113th"); + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(453)).toEqual("453rd"); +}); From 2f1b8757a147b18c2def513027cb207d127f67a7 Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Tue, 14 Jul 2026 17:41:51 +0100 Subject: [PATCH 8/9] Revert accidental changes in package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5ebcdf7334..e4b32166bb 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "keywords": [], "author": "Code Your Future", "license": "ISC", - "devDependencies": { - "jest": "^30.4.2" + "dependencies": { + "jest": "^29.7.0" } } From 715c256f73e0638c2e3c518fdb612f55e95700c6 Mon Sep 17 00:00:00 2001 From: dona-shehu Date: Tue, 14 Jul 2026 17:56:13 +0100 Subject: [PATCH 9/9] Revert package.json to match main --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e4b32166bb..0657e22dd8 100644 --- a/package.json +++ b/package.json @@ -12,4 +12,4 @@ "dependencies": { "jest": "^29.7.0" } -} +} \ No newline at end of file