From 3a52de28546e42d7fe4db24a9a06b3510ae0b35d Mon Sep 17 00:00:00 2001 From: Seti Mussa Date: Sat, 21 Mar 2026 12:16:49 +0000 Subject: [PATCH 1/6] Changes --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..733a681f02 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -17,4 +17,4 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(1)).toEqual("1st"); expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); -}); +}); From 9ffb2652aa58809b816902068d9d93850a824f00 Mon Sep 17 00:00:00 2001 From: Seti Mussa Date: Mon, 30 Mar 2026 19:05:34 +0100 Subject: [PATCH 2/6] I have completed the pratice-tdd --- Sprint-3/2-practice-tdd/count.js | 10 +++++- Sprint-3/2-practice-tdd/count.test.js | 6 ++++ Sprint-3/2-practice-tdd/get-ordinal-number.js | 14 +++++++- .../2-practice-tdd/get-ordinal-number.test.js | 32 +++++++++++++++++-- Sprint-3/2-practice-tdd/repeat-str.js | 4 +-- Sprint-3/2-practice-tdd/repeat-str.test.js | 17 ++++++++++ 6 files changed, 77 insertions(+), 6 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..79977793e5 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 + let count = 0; + + for (let i = 0; i < stringOfCharacters.length; i++) { + if (stringOfCharacters[i] === findCharacter) { + count++; + } + } + + return count; } module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf7..696c932b5a 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,3 +22,9 @@ 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 when character is not found ", () => { + const str = "helo world"; + const char = "z"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..ad5967883d 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,17 @@ function getOrdinalNumber(num) { - return "1st"; + const lastTwoDigits =num % 100; + + // Special cases for 11, 12, and 13 + if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { + return num + "th"; + + } + const lastDigit = num % 10; + if (lastDigit === 1) return num + "st"; + if (lastDigit ===2) return num + "nd"; + if (lastDigit ===3) return num + "rd"; + return num + "th"; + } module.exports = getOrdinalNumber; 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 733a681f02..a55e103068 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -16,5 +16,33 @@ const getOrdinalNumber = require("./get-ordinal-number"); test("should append 'st' for numbers ending with 1, except those ending with 11", () => { expect(getOrdinalNumber(1)).toEqual("1st"); expect(getOrdinalNumber(21)).toEqual("21st"); - expect(getOrdinalNumber(131)).toEqual("131st"); -}); + expect(getOrdinalNumber(41)).toEqual("41st"); +}); + +// Case 2: Numbers ending with 2 (but not 12) +test("should append 'nd' for number ending with 2 except those ending with 12", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(22)).toEqual("22nd"); + expect(getOrdinalNumber(42)).toEqual("42nd"); +}); + +// Case 3: Numbers ending with 3 (but not 13) +test("should append 'rd' for number anding with 3 expect those ending with 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(33)).toEqual("33rd"); + expect(getOrdinalNumber(43)).toEqual("43rd"); +}); + +// Case 4: Number ending with 4 (but not 14) +test("should append 'th' for number ending with 4 expcet those ending with 14", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(44)).toEqual("44th"); + expect(getOrdinalNumber(54)).toEqual("54th"); +}); + +// Case 5: Number ending with 5 (but not 15) +test("should append 'th' for number ending with 5 except those ending with 15", () => { + expect(getOrdinalNumber(5)).toEqual("5th"); + expect(getOrdinalNumber(55)).toEqual("55th"); + expect(getOrdinalNumber(65)).toEqual("65th"); +}); diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b003..f1a4c3e21b 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,5 @@ -function repeatStr() { - return "hellohellohello"; +function repeatStr(n, str) { + return str.repeat(n); } module.exports = repeatStr; diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index a3fc1196c4..38611d75c4 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -20,13 +20,30 @@ test("should repeat the string count times", () => { // Given a target string `str` and a `count` equal to 1, // When the repeatStr function is called with these inputs, // Then it should return the original `str` without repetition. +test("should return the original string when count is 1", () => { + 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 return an empty string when count is 0", () => { + 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("should throw an error when count is negative", () => { + const str = "hello"; + const count = -1; + expect(() => repeatStr(str, count)).toThrow(); +}); From e9f9578833d1ffb07b6fc79c5f9eb37c6b3e97e0 Mon Sep 17 00:00:00 2001 From: Seti Mussa Date: Tue, 31 Mar 2026 16:52:52 +0100 Subject: [PATCH 3/6] Fixed the mistakes and applied the special case --- .../2-practice-tdd/get-ordinal-number.test.js | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) 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 a55e103068..26d6eb765e 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -33,16 +33,20 @@ test("should append 'rd' for number anding with 3 expect those ending with 13", expect(getOrdinalNumber(43)).toEqual("43rd"); }); -// Case 4: Number ending with 4 (but not 14) -test("should append 'th' for number ending with 4 expcet those ending with 14", () => { - expect(getOrdinalNumber(4)).toEqual("4th"); - expect(getOrdinalNumber(44)).toEqual("44th"); - expect(getOrdinalNumber(54)).toEqual("54th"); +// Case 4: Number ending with 11,12, 13 +test("should append 'th' for number ending with 11, 12, 13", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); }); -// Case 5: Number ending with 5 (but not 15) -test("should append 'th' for number ending with 5 except those ending with 15", () => { +// Case 5: Numbers ending with 0, 4, 5, 6, 7, 8, or 9 (but not those ending with 11, 12, or 13) +test("should append 'th' for number ending with 0, 4, 5, 6, 7, 8, or 9 ,(but not those ending with 11, 12, or 13)", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); expect(getOrdinalNumber(5)).toEqual("5th"); - expect(getOrdinalNumber(55)).toEqual("55th"); - expect(getOrdinalNumber(65)).toEqual("65th"); + expect(getOrdinalNumber(6)).toEqual("6th"); + expect(getOrdinalNumber(7)).toEqual("7th"); + expect(getOrdinalNumber(8)).toEqual("8th"); + expect(getOrdinalNumber(9)).toEqual("9th"); + expect(getOrdinalNumber(10)).toEqual("10th"); }); From 292dd0fa24264b3cc8f0ac0c38067d5305203126 Mon Sep 17 00:00:00 2001 From: Seti Mussa Date: Tue, 31 Mar 2026 17:02:31 +0100 Subject: [PATCH 4/6] Added more test for getOrdinalNumber implementing --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 26d6eb765e..c4984b1c54 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -27,17 +27,20 @@ test("should append 'nd' for number ending with 2 except those ending with 12", }); // Case 3: Numbers ending with 3 (but not 13) -test("should append 'rd' for number anding with 3 expect those ending with 13", () => { +test("should append 'rd' for number ending with 3, except those ending with 13", () => { expect(getOrdinalNumber(3)).toEqual("3rd"); expect(getOrdinalNumber(33)).toEqual("33rd"); expect(getOrdinalNumber(43)).toEqual("43rd"); }); -// Case 4: Number ending with 11,12, 13 -test("should append 'th' for number ending with 11, 12, 13", () => { +// Case 4: Number ending with 11,12, or 13 +test("should append 'th' for number ending with 11, 12, or 13", () => { expect(getOrdinalNumber(11)).toEqual("11th"); expect(getOrdinalNumber(12)).toEqual("12th"); expect(getOrdinalNumber(13)).toEqual("13th"); + expect(getOrdinalNumber(111)).toEqual("111th"); + expect(getOrdinalNumber(112)).toEqual("112th"); + expect(getOrdinalNumber(113)).toEqual("113th"); }); // Case 5: Numbers ending with 0, 4, 5, 6, 7, 8, or 9 (but not those ending with 11, 12, or 13) From dc0f3f72cd1b34492758ec84bec5fd15e276b2eb Mon Sep 17 00:00:00 2001 From: Seti Mussa Date: Tue, 31 Mar 2026 17:15:45 +0100 Subject: [PATCH 5/6] fix the repeat-str --- Sprint-3/2-practice-tdd/repeat-str.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index f1a4c3e21b..199f7fe7ec 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,7 @@ -function repeatStr(n, str) { - return str.repeat(n); -} +function repeatStr(str, count) { + if (count < 0) { + throw new Error("Count cannot be negative"); + } -module.exports = repeatStr; + return str.repeat(count); +} From 1aac84e24f6943c393866c08abefe2c3b41d1223 Mon Sep 17 00:00:00 2001 From: Seti Mussa Date: Tue, 31 Mar 2026 17:21:05 +0100 Subject: [PATCH 6/6] Fixed spelling mistakes --- Sprint-3/2-practice-tdd/repeat-str.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 199f7fe7ec..0c5973b786 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -5,3 +5,4 @@ function repeatStr(str, count) { return str.repeat(count); } +module.exports = repeatStr;