From cff3419aa8ba8097ac918830b1c4ddd1b1d5c7a2 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Fri, 16 Oct 2026 23:56:57 +0100 Subject: [PATCH 01/51] wrote a test to count a character in a string where that character doent exit in the string,test failed --- practice-tdd/count.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index cb3aaae59..10827db29 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -22,3 +22,10 @@ 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 count multiple occurences of character", () => { + const str = "aaaaa"; + const char = "c"; + const count = countChar(str, char); + expect(count).toEqual(3); +}); From e3a0787bd356c35594f375cfb6487ed9d0d7d149 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 00:15:47 +0100 Subject: [PATCH 02/51] edited the test --- practice-tdd/count.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index 10827db29..c30e55167 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -27,5 +27,5 @@ test(" Should count multiple occurences of character", () => { const str = "aaaaa"; const char = "c"; const count = countChar(str, char); - expect(count).toEqual(3); + expect(count).toEqual(0); }); From 6cd309798f2052fb97cba48033259d396d43de36 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 00:17:40 +0100 Subject: [PATCH 03/51] made a change to the code, test passed --- practice-tdd/count.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/practice-tdd/count.js b/practice-tdd/count.js index 5518c5712..f344b532d 100644 --- a/practice-tdd/count.js +++ b/practice-tdd/count.js @@ -1,3 +1,6 @@ export function countChar(stringOfCharacters, findCharacter) { - return 5 + if (stringOfCharacters[0] == findCharacter) { + return 5; + } + return 0; } From 5418d115414e83751898b2057e97630a5ed1655a Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 00:32:06 +0100 Subject: [PATCH 04/51] wrote a test , test failed. --- practice-tdd/count.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index c30e55167..8c313df19 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -29,3 +29,10 @@ test(" Should count multiple occurences of character", () => { const count = countChar(str, char); expect(count).toEqual(0); }); + +test("should count multiple occurences of character", () => { + const str = "acc"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(1); +}); From 86ffa329a36558f1bdde6eb378f10b188bca371e Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 00:38:11 +0100 Subject: [PATCH 05/51] added some line in the code to make the test pass, two more test failed --- practice-tdd/count.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/practice-tdd/count.js b/practice-tdd/count.js index f344b532d..8544ee18e 100644 --- a/practice-tdd/count.js +++ b/practice-tdd/count.js @@ -1,6 +1,7 @@ export function countChar(stringOfCharacters, findCharacter) { - if (stringOfCharacters[0] == findCharacter) { - return 5; + let i = 0; + if (stringOfCharacters[i] == findCharacter) { + return i++; } return 0; } From a23a6a5eac92b266022b0e4ca07ac1c23d7a2406 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 01:35:54 +0100 Subject: [PATCH 06/51] added some code to make the test pass,test passed --- practice-tdd/count.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/practice-tdd/count.js b/practice-tdd/count.js index 8544ee18e..56a747f3c 100644 --- a/practice-tdd/count.js +++ b/practice-tdd/count.js @@ -1,7 +1,9 @@ export function countChar(stringOfCharacters, findCharacter) { - let i = 0; - if (stringOfCharacters[i] == findCharacter) { - return i++; + let count = 0; + for (let i = 0; i < stringOfCharacters.length; i++) { + if (stringOfCharacters[i] == findCharacter[0]) { + count = count + 1; + } } - return 0; + return count; } From 4fffb004384bb5dc42bf0a8f83ec5f8abf3f25e1 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 01:49:15 +0100 Subject: [PATCH 07/51] wrote a test and it passed --- practice-tdd/count.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index 8c313df19..da27a50f3 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -36,3 +36,9 @@ test("should count multiple occurences of character", () => { const count = countChar(str, char); expect(count).toEqual(1); }); +test("should count multiple occurences of character", () => { + const str = "AAAa"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(1); +}); From 0b8b95385391cadffb12fddcd6c41a04d7a4a518 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 01:55:10 +0100 Subject: [PATCH 08/51] added a test which includes number in the string,test passed --- practice-tdd/count.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index da27a50f3..2f987de43 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -42,3 +42,9 @@ test("should count multiple occurences of character", () => { const count = countChar(str, char); expect(count).toEqual(1); }); +test("should count multiple occurences of character", () => { + const str = "11aa"; + const char = "1"; + const count = countChar(str, char); + expect(count).toEqual(2); +}); From 623a0a66b5b58885df9b959d4a4261420b9674bb Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 01:57:38 +0100 Subject: [PATCH 09/51] =?UTF-8?q?added=20a=20test=20for=20a=20=C2=A3=20cha?= =?UTF-8?q?racter,test=20passed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- practice-tdd/count.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index 2f987de43..e7b2ef0a4 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -48,3 +48,9 @@ test("should count multiple occurences of character", () => { const count = countChar(str, char); expect(count).toEqual(2); }); +test("should count multiple occurences of character", () => { + const str = "£100"; + const char = "£"; + const count = countChar(str, char); + expect(count).toEqual(1); +}); From cbd3ff3464ea96a861d18ed0550cc81e7fb95085 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 02:09:07 +0100 Subject: [PATCH 10/51] added a test that would count space between words in a string --- practice-tdd/count.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index e7b2ef0a4..f8dd79a15 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -54,3 +54,9 @@ test("should count multiple occurences of character", () => { const count = countChar(str, char); expect(count).toEqual(1); }); +test("should count multiple occurences of character", () => { + const str = "let's play tag"; + const char = " "; + const count = countChar(str, char); + expect(count).toEqual(2); +}); From e0136e63b5033639783dcee8f3f81a9c488229ef Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 02:14:49 +0100 Subject: [PATCH 11/51] added a test to count characters in group of words in a string, test passed --- practice-tdd/count.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index f8dd79a15..c495bc5f0 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -60,3 +60,9 @@ test("should count multiple occurences of character", () => { const count = countChar(str, char); expect(count).toEqual(2); }); +test("should count multiple occurences of character", () => { + const str = "let's play tag"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(2); +}); From 4a71d58d1fb7ce878f4b433466cf893adaf619fc Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 02:34:20 +0100 Subject: [PATCH 12/51] test case 1 failed, fixed the code, test passed. --- practice-tdd/get-ordinal-number.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 5c6291f5e..4022152ab 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,3 +1,3 @@ export function getOrdinalNumber(num) { - return "1st"; + return `${num}st`; } From 68e09e346ccfa712a1c4eca910a79c452ca2dc7e Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 03:28:01 +0100 Subject: [PATCH 13/51] wrote a test for case 2. Test failed --- practice-tdd/get-ordinal-number.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index e23174a18..2c0e4fc44 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -18,3 +18,9 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" 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 1, except those ending with 11", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(22)).toEqual("22nd"); + expect(getOrdinalNumber(132)).toEqual("132nd"); +}); From 9b5152ed1c1da17bbb6d5009731a281082e58167 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 03:28:49 +0100 Subject: [PATCH 14/51] wrote a code to pass the test.test passed --- practice-tdd/get-ordinal-number.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 4022152ab..5248ed8d4 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,3 +1,8 @@ export function getOrdinalNumber(num) { - return `${num}st`; + let numStr = num.toString(); + + if (numStr.slice(-1) == "1") { + return `${num}st`; + } + return `${num}nd`; } From dd1a4529f5d067b10bbbc10cc8eb29d144c12987 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 03:43:00 +0100 Subject: [PATCH 15/51] wrote a test for case 3, test failed. --- practice-tdd/get-ordinal-number.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 2c0e4fc44..cef919bca 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -24,3 +24,9 @@ test("should append 'nd' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(22)).toEqual("22nd"); expect(getOrdinalNumber(132)).toEqual("132nd"); }); +//Case 3: Number ending with 3(but not 13) +test("should append 'rd' for numbers ending with 1, except those ending with 11", () => { + expect(getOrdinalNumber(3)).toEqual("2nd"); + expect(getOrdinalNumber(23)).toEqual("22nd"); + expect(getOrdinalNumber(133)).toEqual("132nd"); +}); From 650bd92e6baa9a0810ccc3fd0a8ed80710a33078 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 12:45:27 +0100 Subject: [PATCH 16/51] two tests failed so made amend on the code and one test passed,one test failed --- practice-tdd/get-ordinal-number.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 5248ed8d4..a92485da3 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -4,5 +4,8 @@ export function getOrdinalNumber(num) { if (numStr.slice(-1) == "1") { return `${num}st`; } - return `${num}nd`; + if (numStr.slice(-1) == "2") { + return `${num}nd`; + } + return `${num}rd`; } From a7c42abf4ce5fe02e822d7c27ea84b82ab4f359c Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 12:48:17 +0100 Subject: [PATCH 17/51] make changes to the test code and test passed --- practice-tdd/get-ordinal-number.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index cef919bca..deb845c04 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -26,7 +26,7 @@ test("should append 'nd' for numbers ending with 1, except those ending with 11" }); //Case 3: Number ending with 3(but not 13) test("should append 'rd' for numbers ending with 1, except those ending with 11", () => { - expect(getOrdinalNumber(3)).toEqual("2nd"); - expect(getOrdinalNumber(23)).toEqual("22nd"); - expect(getOrdinalNumber(133)).toEqual("132nd"); + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(133)).toEqual("133rd"); }); From 7f7deb48541b152e7dae0096d53147a03896fee2 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 12:53:27 +0100 Subject: [PATCH 18/51] add atest to the testing file and test failed --- practice-tdd/get-ordinal-number.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index deb845c04..1556477f5 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -30,3 +30,10 @@ test("should append 'rd' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(23)).toEqual("23rd"); expect(getOrdinalNumber(133)).toEqual("133rd"); }); +test("should append 'th' for numbers ending with (4,5,6,7,8,9,0)", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(15)).toEqual("15th"); + expect(getOrdinalNumber(58)).toEqual("58th"); + expect(getOrdinalNumber(100)).toEqual("100th"); +}); From 5b59e1736261f9c48eda68d0b5259f5e64df4ce0 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 13:18:26 +0100 Subject: [PATCH 19/51] added and amended in the code and the test passed --- practice-tdd/get-ordinal-number.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index a92485da3..7eb4c193b 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -7,5 +7,8 @@ export function getOrdinalNumber(num) { if (numStr.slice(-1) == "2") { return `${num}nd`; } - return `${num}rd`; + if (numStr.slice(-1) == "3") { + return `${num}rd`; + } + return `${num}th`; } From 494887fc7623b09171f45a093fb0579d5c5b7fb5 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 13:35:05 +0100 Subject: [PATCH 20/51] added a test for case 5, exception numbers, test failed. --- practice-tdd/get-ordinal-number.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 1556477f5..ff1c769e4 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -30,6 +30,7 @@ test("should append 'rd' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(23)).toEqual("23rd"); expect(getOrdinalNumber(133)).toEqual("133rd"); }); +//csae4 : Number ending between 4 and 9 including (0,4,9) test("should append 'th' for numbers ending with (4,5,6,7,8,9,0)", () => { expect(getOrdinalNumber(4)).toEqual("4th"); expect(getOrdinalNumber(10)).toEqual("10th"); @@ -37,3 +38,9 @@ test("should append 'th' for numbers ending with (4,5,6,7,8,9,0)", () => { expect(getOrdinalNumber(58)).toEqual("58th"); expect(getOrdinalNumber(100)).toEqual("100th"); }); +//Case 5: the exception numbers left out in all the cases(11,12,13) +test("should append 'th' for numbers 11, 12, 13", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); +}); From 4453a23559efbc6db78fd0c0902c8dbae69556bd Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 14:07:54 +0100 Subject: [PATCH 21/51] made changes to the code and test passed on case 5. --- practice-tdd/get-ordinal-number.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 7eb4c193b..6328e7843 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,14 +1,17 @@ export function getOrdinalNumber(num) { let numStr = num.toString(); - if (numStr.slice(-1) == "1") { + if (numStr.slice(-1) == "1" && num != 11) { return `${num}st`; } - if (numStr.slice(-1) == "2") { + if (numStr.slice(-1) == "2" && num != 12) { return `${num}nd`; } - if (numStr.slice(-1) == "3") { + if (numStr.slice(-1) == "3" && num != 13) { return `${num}rd`; } + if (num == 11 || num == 12 || num == 13) { + return `${num}th`; + } return `${num}th`; } From 91c2378ffe799b31ba96feffec6b941da1d4d1f0 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 15:09:55 +0100 Subject: [PATCH 22/51] added a test to throw an error when the argument is 0. Test failed --- practice-tdd/get-ordinal-number.test.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index ff1c769e4..272c9e26f 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -30,7 +30,7 @@ test("should append 'rd' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(23)).toEqual("23rd"); expect(getOrdinalNumber(133)).toEqual("133rd"); }); -//csae4 : Number ending between 4 and 9 including (0,4,9) +//case 4 : Number ending between 4 and 9 including (0,4,9) test("should append 'th' for numbers ending with (4,5,6,7,8,9,0)", () => { expect(getOrdinalNumber(4)).toEqual("4th"); expect(getOrdinalNumber(10)).toEqual("10th"); @@ -44,3 +44,7 @@ test("should append 'th' for numbers 11, 12, 13", () => { expect(getOrdinalNumber(12)).toEqual("12th"); expect(getOrdinalNumber(13)).toEqual("13th"); }); +//case 5 now we have come to the last one 0 +test(` should throw an error when num is 0`, () => { + expect(() => getOrdinalNumber(0)).toThrow(`Invalid Input`); +}); From 87eb71e5db120c2b7ad002f3b5bd36415e296eb6 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 15:14:42 +0100 Subject: [PATCH 23/51] added a code that throws an error when num is passed with a value zero,test passed. --- practice-tdd/get-ordinal-number.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 6328e7843..c4c5b2fa4 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,6 +1,8 @@ export function getOrdinalNumber(num) { let numStr = num.toString(); - + if (num == 0) { + throw new Error("Invalid Input"); + } if (numStr.slice(-1) == "1" && num != 11) { return `${num}st`; } From 55e6ea00959fed8e7b596b2a8a13690ef4e34110 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 17:25:24 +0100 Subject: [PATCH 24/51] wrote a test with count =2, test failed --- practice-tdd/repeat-str.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 8a7036102..b26f7110d 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -15,6 +15,12 @@ test("should repeat the string count times", () => { const repeatedStr = repeatStr(str, count); expect(repeatedStr).toEqual("hellohellohello"); }); +test("should repeat the string count times", () => { + const str = "hello"; + const count = 2; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("hellohello"); +}); // Case: handle count of 1: // Given a target string `str` and a `count` equal to 1, From 2a2811a5774498128fba570f6094fcc4ff6580c5 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 17:36:14 +0100 Subject: [PATCH 25/51] added a code to make the test failed pass. Success. --- practice-tdd/repeat-str.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index af273f3b0..de31d3bad 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,5 +1,8 @@ -export function repeatStr() { +export function repeatStr(str, count) { // 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. + if (count == 2) { + return "hellohello"; + } return "hellohellohello"; } From 119aabbe5cd221a92894ff44da87986ca07e07c8 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 17:41:46 +0100 Subject: [PATCH 26/51] added a test for the case count=1, test failed --- practice-tdd/repeat-str.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index b26f7110d..bde23d463 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -26,7 +26,12 @@ 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 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, From e8ae9bbc7563035f576b2f5d302e20ec257368cf Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 17:44:31 +0100 Subject: [PATCH 27/51] added a code to make the test pass four count =1, test passed --- practice-tdd/repeat-str.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index de31d3bad..e51be1b7a 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,8 +1,12 @@ export function repeatStr(str, count) { // 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. + if (count == 1) { + return str; + } if (count == 2) { return "hellohello"; } + return "hellohellohello"; } From c89337cc6fc9346be1b6b8971393bc3b870d6852 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 17:47:39 +0100 Subject: [PATCH 28/51] added a test for case where count=0, test failed --- practice-tdd/repeat-str.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index bde23d463..20a5ee4b1 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -36,7 +36,12 @@ test("should repeat the string count times", () => { // 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("hello"); +}); // Case: Handle negative count: // Given a target string `str` and a negative integer `count`, // When the repeatStr function is called with these inputs, From a87428c943be2f42f06040671562ed428ca8c75d Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 18:04:49 +0100 Subject: [PATCH 29/51] made a small change to the test file on the expected string --- practice-tdd/repeat-str.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 20a5ee4b1..731c1a69a 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -40,7 +40,7 @@ test("should repeat the string count times", () => { const str = "hello"; const count = 0; const repeatedStr = repeatStr(str, count); - expect(repeatedStr).toEqual("hello"); + expect(repeatedStr).toEqual(" "); }); // Case: Handle negative count: // Given a target string `str` and a negative integer `count`, From ad818d2f80411c99e0fa4022bdb97b697be17fb4 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 18:22:58 +0100 Subject: [PATCH 30/51] wrote a code for case count=0, and test passed --- practice-tdd/repeat-str.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index e51be1b7a..d70beda65 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,6 +1,9 @@ export function repeatStr(str, count) { // 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. + if (count == 0) { + return " "; + } if (count == 1) { return str; } From 0f414c7b071dfd6a45ad335a6ee8638ab80673f8 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 18:43:37 +0100 Subject: [PATCH 31/51] added a test for -ve counts and the code will throw an error.test failed --- practice-tdd/repeat-str.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 731c1a69a..8f8745d91 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -46,3 +46,8 @@ test("should repeat the string count times", () => { // 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 repeat the string count times", () => { + expect(() => repeatStr("hello", -1)).toThrow( + "Negative counts are not valid " + ); +}); From 2e069e9f845723792645744c01462d237fdfa9cc Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 18:53:01 +0100 Subject: [PATCH 32/51] count<0 in code is added and the test passed by throwing error when counts is negative --- practice-tdd/repeat-str.js | 3 +++ practice-tdd/repeat-str.test.js | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index d70beda65..bb43640f2 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,6 +1,9 @@ export function repeatStr(str, count) { // 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. + if (count < 0) { + throw new Error("Negative counts are not valid"); + } if (count == 0) { return " "; } diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 8f8745d91..77aa1de65 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -47,7 +47,5 @@ test("should repeat the string count times", () => { // When the repeatStr function is called with these inputs, // Then it should throw an error, as negative counts are not valid. test("should repeat the string count times", () => { - expect(() => repeatStr("hello", -1)).toThrow( - "Negative counts are not valid " - ); + expect(() => repeatStr("hello", -1)).toThrow("Negative counts are not valid"); }); From 0cbd674c727064b561a702f32ec556e4ba43e2bd Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 18:56:28 +0100 Subject: [PATCH 33/51] added a test that would return 4 hello.test failed --- practice-tdd/repeat-str.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 77aa1de65..4a1d16268 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -21,6 +21,12 @@ test("should repeat the string count times", () => { const repeatedStr = repeatStr(str, count); expect(repeatedStr).toEqual("hellohello"); }); +test("should repeat the string count times", () => { + const str = "hello"; + const count = 4; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("hellohellohellohello"); +}); // Case: handle count of 1: // Given a target string `str` and a `count` equal to 1, From b6e57ae71e96e82b35de86170f66ec012c9cc299 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 21:46:40 +0100 Subject: [PATCH 34/51] added a code that woud repeat a string count time. test passed --- practice-tdd/repeat-str.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index bb43640f2..068ac1ea8 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,6 +1,7 @@ export function repeatStr(str, count) { // 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. + let repeatedStr = str; if (count < 0) { throw new Error("Negative counts are not valid"); } @@ -13,6 +14,8 @@ export function repeatStr(str, count) { if (count == 2) { return "hellohello"; } - - return "hellohellohello"; + for (let i = 1; i < count; i++) { + repeatedStr += str; + } + return repeatedStr; } From 6fd92cef0644b62c760391a8f41b5e46142a534e Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 21:51:02 +0100 Subject: [PATCH 35/51] removed duplicated codes(refractor time) --- practice-tdd/repeat-str.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index 068ac1ea8..42ea3727a 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,6 +1,4 @@ export function repeatStr(str, count) { - // 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. let repeatedStr = str; if (count < 0) { throw new Error("Negative counts are not valid"); @@ -8,12 +6,6 @@ export function repeatStr(str, count) { if (count == 0) { return " "; } - if (count == 1) { - return str; - } - if (count == 2) { - return "hellohello"; - } for (let i = 1; i < count; i++) { repeatedStr += str; } From 79f8acd57c2189c700f036eb01048a10fa54aeb3 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 21:53:14 +0100 Subject: [PATCH 36/51] refractor code --- practice-tdd/repeat-str.test.js | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 4a1d16268..7c6cd1184 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -1,13 +1,5 @@ // Implement a function repeatStr import { repeatStr } from "./repeat-str.js"; -// Given a target string `str` and a positive integer `count`, -// When the repeatStr function is called with these inputs, -// Then it should: - -// Case: handle multiple repetitions: -// Given a target string `str` and a positive integer `count` greater than 1, -// When the repeatStr function is called with these inputs, -// Then it should return a string that contains the original `str` repeated `count` times. test("should repeat the string count times", () => { const str = "hello"; @@ -29,9 +21,7 @@ test("should repeat the string count times", () => { }); // Case: handle count of 1: -// 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 repeat the string count times", () => { const str = "hello"; const count = 1; @@ -39,9 +29,7 @@ test("should repeat the string count times", () => { 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; @@ -49,9 +37,7 @@ test("should repeat the string count times", () => { 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 repeat the string count times", () => { expect(() => repeatStr("hello", -1)).toThrow("Negative counts are not valid"); }); From 20e8438e370bb4a486da983af8d8a09ddfaa215a Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 21:55:39 +0100 Subject: [PATCH 37/51] cleaning up the code and format using prettier --- practice-tdd/get-ordinal-number.test.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 272c9e26f..481788310 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -1,18 +1,7 @@ import { getOrdinalNumber } from "./get-ordinal-number.js"; -// In this week's prep, we started implementing getOrdinalNumber. - -// Continue testing and implementing getOrdinalNumber for additional cases. -// Write your tests using Jest — remember to run your tests often for continual feedback. - -// To ensure thorough testing, we need broad scenarios that cover all possible cases. -// Listing individual values, however, can quickly lead to an unmanageable number of test cases. -// Instead of writing tests for individual numbers, consider grouping all possible input values -// into meaningful categories. Then, select representative samples from each category to test. -// This approach improves coverage and makes our tests easier to maintain. // Case 1: Numbers ending with 1 (but not 11) -// 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(1)).toEqual("1st"); expect(getOrdinalNumber(21)).toEqual("21st"); From 217ef1918836712c73433d44c8bcad975e9539f1 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 17 Oct 2026 21:57:43 +0100 Subject: [PATCH 38/51] cleaning up the code --- practice-tdd/count.test.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index c495bc5f0..c24592b0a 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -1,14 +1,7 @@ // implement a function countChar that counts the number of times a character occurs in a string import { countChar } from "./count.js"; -// Given a string `str` and a single character `char` to search for, -// When the countChar function is called with these inputs, -// Then it should: // Scenario: Multiple Occurrences -// Given the input string `str`, -// And a character `char` that occurs one or more times in `str` (e.g., 'a' in 'aaaaa'), -// When the function is called with these inputs, -// Then it should correctly count occurrences of `char`. test("should count multiple occurrences of a character", () => { const str = "aaaaa"; @@ -18,10 +11,6 @@ test("should count multiple occurrences of a character", () => { }); // Scenario: No Occurrences -// Given the input string `str`, -// 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 count multiple occurences of character", () => { const str = "aaaaa"; From 9551f77628b84bc7b59d7c3fecf60137b17d86ea Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Mon, 19 Oct 2026 21:06:55 +0100 Subject: [PATCH 39/51] changed all the test names,and added a test for throwing an Error if given more than one character --- practice-tdd/count.test.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index c24592b0a..85351e0b2 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -3,7 +3,7 @@ import { countChar } from "./count.js"; // Scenario: Multiple Occurrences -test("should count multiple occurrences of a character", () => { +test("should count multiple occurrences of a character 'a' ", () => { const str = "aaaaa"; const char = "a"; const count = countChar(str, char); @@ -12,46 +12,51 @@ test("should count multiple occurrences of a character", () => { // Scenario: No Occurrences -test(" Should count multiple occurences of character", () => { +test(" Should count 0", () => { const str = "aaaaa"; const char = "c"; const count = countChar(str, char); expect(count).toEqual(0); }); -test("should count multiple occurences of character", () => { +test("should count a character with strings of different characters", () => { const str = "acc"; const char = "a"; const count = countChar(str, char); expect(count).toEqual(1); }); -test("should count multiple occurences of character", () => { +test("should count a character with strings of different characters that includes uppercase", () => { const str = "AAAa"; const char = "a"; const count = countChar(str, char); expect(count).toEqual(1); }); -test("should count multiple occurences of character", () => { +test("should count multiple occurences of character when given with numbers", () => { const str = "11aa"; const char = "1"; const count = countChar(str, char); expect(count).toEqual(2); }); -test("should count multiple occurences of character", () => { +test("should count multiple occurences of character with signs", () => { const str = "£100"; const char = "£"; const count = countChar(str, char); expect(count).toEqual(1); }); -test("should count multiple occurences of character", () => { +test("should count multiple occurences of character empty space", () => { const str = "let's play tag"; const char = " "; const count = countChar(str, char); expect(count).toEqual(2); }); -test("should count multiple occurences of character", () => { +test("should count multiple occurences of character in a sentence", () => { const str = "let's play tag"; const char = "a"; const count = countChar(str, char); expect(count).toEqual(2); }); +test("should throw an error when findCharacter receives more than one character", () => { + expect(() => { + countChar("aaaaaaanaaa", "an"); + }).toThrow(`Invalid Input,only character is allowed`); +}); From b1e9a88cd150ad980ffec94cef4f42297cd5b898 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Mon, 19 Oct 2026 21:07:45 +0100 Subject: [PATCH 40/51] added a code to throw an error if findCharacter is more than one character --- practice-tdd/count.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/practice-tdd/count.js b/practice-tdd/count.js index 56a747f3c..e65aa9100 100644 --- a/practice-tdd/count.js +++ b/practice-tdd/count.js @@ -1,5 +1,8 @@ export function countChar(stringOfCharacters, findCharacter) { let count = 0; + if (findCharacter.length != 1) { + throw new Error(`Invalid Input,only character is allowed`); + } for (let i = 0; i < stringOfCharacters.length; i++) { if (stringOfCharacters[i] == findCharacter[0]) { count = count + 1; From 63986b592577f2f082d590ec85e47298d04e9066 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 20 Oct 2026 00:30:50 +0100 Subject: [PATCH 41/51] added two tests for an empty string and a space --- practice-tdd/count.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index 85351e0b2..29bf964e7 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -55,6 +55,18 @@ test("should count multiple occurences of character in a sentence", () => { const count = countChar(str, char); expect(count).toEqual(2); }); +test("should count multiple occurences of character in an empty string", () => { + const str = ""; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); +test("should count multiple occurences of character in a sentence", () => { + const str = " "; + const char = " "; + const count = countChar(str, char); + expect(count).toEqual(1); +}); test("should throw an error when findCharacter receives more than one character", () => { expect(() => { countChar("aaaaaaanaaa", "an"); From cd87177a1a21760f6497bd02f2719efc4bbe5f4c Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 20 Oct 2026 19:48:50 +0100 Subject: [PATCH 42/51] added code to make the test past for big numbers ending with 11,like111 --- practice-tdd/get-ordinal-number.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index c4c5b2fa4..7358bc35b 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -3,17 +3,17 @@ export function getOrdinalNumber(num) { if (num == 0) { throw new Error("Invalid Input"); } - if (numStr.slice(-1) == "1" && num != 11) { + + if (numStr.slice(-1) == "1" && numStr.slice(-2) != 11) { return `${num}st`; } - if (numStr.slice(-1) == "2" && num != 12) { + + if (numStr.slice(-1) == "2" && numStr.slice(-2) != 12) { return `${num}nd`; } - if (numStr.slice(-1) == "3" && num != 13) { + if (numStr.slice(-1) == "3" && numStr.slice(-2) != 13) { return `${num}rd`; } - if (num == 11 || num == 12 || num == 13) { - return `${num}th`; - } + return `${num}th`; } From 19060bccae252902d325211f5542a9469cead30d Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 20 Oct 2026 19:57:03 +0100 Subject: [PATCH 43/51] updated the case name added some more test for numbers ending with 11 and added a test for empty string --- practice-tdd/get-ordinal-number.test.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 481788310..96b33dfba 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -1,25 +1,25 @@ import { getOrdinalNumber } from "./get-ordinal-number.js"; -// Case 1: Numbers ending with 1 (but not 11) -. +// Case 1: Numbers ending with 1 (but not 11). 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"); }); // Case 2: Numbers ending with 2(but not 12). -test("should append 'nd' for numbers ending with 1, except those ending with 11", () => { +test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { expect(getOrdinalNumber(2)).toEqual("2nd"); expect(getOrdinalNumber(22)).toEqual("22nd"); expect(getOrdinalNumber(132)).toEqual("132nd"); }); //Case 3: Number ending with 3(but not 13) -test("should append 'rd' for numbers ending with 1, except those ending with 11", () => { +test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { expect(getOrdinalNumber(3)).toEqual("3rd"); expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(103)).toEqual("103rd"); expect(getOrdinalNumber(133)).toEqual("133rd"); }); -//case 4 : Number ending between 4 and 9 including (0,4,9) +//case 4 : Number ending 4,5,6,7,8,9 and 0. test("should append 'th' for numbers ending with (4,5,6,7,8,9,0)", () => { expect(getOrdinalNumber(4)).toEqual("4th"); expect(getOrdinalNumber(10)).toEqual("10th"); @@ -32,8 +32,17 @@ test("should append 'th' for numbers 11, 12, 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 now we have come to the last one 0 + +//case 6 now we have come to the last one 0 test(` should throw an error when num is 0`, () => { expect(() => getOrdinalNumber(0)).toThrow(`Invalid Input`); }); + +//case 7 how about when empty string is the argument +test(`Should throw an error when num is empty string`, () => { + expect(() => getOrdinalNumber(" ")).toThrow(`Invalid Input`); +}); From 5fab553cd9004fd97199995d36da3f5672bbc2e8 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 20 Oct 2026 19:58:22 +0100 Subject: [PATCH 44/51] edited a code to include error to throw for empty String --- practice-tdd/get-ordinal-number.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 7358bc35b..4aa4ec781 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,6 +1,6 @@ export function getOrdinalNumber(num) { let numStr = num.toString(); - if (num == 0) { + if (num == 0 || num == " ") { throw new Error("Invalid Input"); } From b87e5f44d580438d4ca809c8e4d6dcfe52212c16 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 20 Oct 2026 20:53:58 +0100 Subject: [PATCH 45/51] wrote back the comment as aadvised and added two more tested --- practice-tdd/get-ordinal-number.test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 96b33dfba..fd8772a3b 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -1,11 +1,25 @@ import { getOrdinalNumber } from "./get-ordinal-number.js"; +// In this week's prep, we started implementing getOrdinalNumber. +// Continue testing and implementing getOrdinalNumber for additional cases. +// Write your tests using Jest — remember to run your tests often for continual feedback. +// To ensure thorough testing, we need broad scenarios that cover all possible cases. +// Listing individual values, however, can quickly lead to an unmanageable number of test cases. +// Instead of writing tests for individual numbers, consider grouping all possible input values +// into meaningful categories. Then, select representative samples from each category to test. +// This approach improves coverage and makes our tests easier to maintain. + +// Case 1: Numbers ending with 1 (but not 11) +// When the number ends with 1, except those ending with 11, +// Then the function should return a string by appending "st" to the number. + // Case 1: Numbers ending with 1 (but not 11). 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"); }); + // 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(2)).toEqual("2nd"); @@ -46,3 +60,11 @@ test(` should throw an error when num is 0`, () => { test(`Should throw an error when num is empty string`, () => { expect(() => getOrdinalNumber(" ")).toThrow(`Invalid Input`); }); +// Case 8 how about when num is -ve number +test(`should throw an Error when num is -ve number`, () => { + expect(() => getOrdinalNumber(-5).toThrow(`Invalid Input`)); +}); +//case 9 when num is decimal number +test(`Should throw an Error when num is decimal number`, () => { + expect(() => getOrdinalNumber(1.5).toThrow(`Invalid Input`)); +}); From 2aed0032a405f535783695aa5817b7752bbe68cb Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 20 Oct 2026 20:55:04 +0100 Subject: [PATCH 46/51] Edited some cods to make the two tests added for -ve and decimal numbers. Both passed --- practice-tdd/get-ordinal-number.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 4aa4ec781..88ea1b03b 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,6 +1,6 @@ export function getOrdinalNumber(num) { let numStr = num.toString(); - if (num == 0 || num == " ") { + if (num <= 0 || num == " " || numStr.includes(".")) { throw new Error("Invalid Input"); } From 942dc2b8541001620cb8bca8c8e45dcc3f5a4906 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 20 Oct 2026 21:58:55 +0100 Subject: [PATCH 47/51] added back the comment as advised and added a Math method to help with a decimal input --- practice-tdd/repeat-str.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index 42ea3727a..eafb444b3 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,11 +1,18 @@ export function repeatStr(str, count) { + // 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. + let repeatedStr = str; + count = Math.floor(count); + if (count < 0) { throw new Error("Negative counts are not valid"); } if (count == 0) { - return " "; + return ""; } + for (let i = 1; i < count; i++) { repeatedStr += str; } From 52a1d813a47c0658ba16f58c1d824ff3e443cb34 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 20 Oct 2026 22:00:28 +0100 Subject: [PATCH 48/51] added test cases for decimal fixed the name given to the test --- practice-tdd/repeat-str.test.js | 38 ++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 7c6cd1184..ffefe66a9 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -1,43 +1,51 @@ // Implement a function repeatStr import { repeatStr } from "./repeat-str.js"; -test("should repeat the string count times", () => { +// Case: handle count of 1, 2, 3, 4: + +test("should repeat the string 1 times", () => { const str = "hello"; - const count = 3; + const count = 1; const repeatedStr = repeatStr(str, count); - expect(repeatedStr).toEqual("hellohellohello"); + expect(repeatedStr).toEqual("hello"); }); -test("should repeat the string count times", () => { +test("should repeat the string 2 times", () => { const str = "hello"; const count = 2; const repeatedStr = repeatStr(str, count); expect(repeatedStr).toEqual("hellohello"); }); -test("should repeat the string count times", () => { +test("should repeat the string 3 times", () => { + const str = "hello"; + const count = 3; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("hellohellohello"); +}); +test("should repeat the string 4 times", () => { const str = "hello"; const count = 4; const repeatedStr = repeatStr(str, count); expect(repeatedStr).toEqual("hellohellohellohello"); }); +// Case: Handle count of 0: -// Case: handle count of 1: - -test("should repeat the string count times", () => { +test("should repeat the string 0 times", () => { const str = "hello"; - const count = 1; + const count = 0; const repeatedStr = repeatStr(str, count); - expect(repeatedStr).toEqual("hello"); + expect(repeatedStr).toEqual(""); }); -// Case: Handle count of 0: +//case: Handle decimal count -test("should repeat the string count times", () => { +test("should repeat the stringthe whole number in the count times", () => { const str = "hello"; - const count = 0; + const count = 2.5; const repeatedStr = repeatStr(str, count); - expect(repeatedStr).toEqual(" "); + expect(repeatedStr).toEqual("hellohello"); }); + // Case: Handle negative count: -test("should repeat the string count times", () => { +test("should throw an error when -1 count is given", () => { expect(() => repeatStr("hello", -1)).toThrow("Negative counts are not valid"); }); From 3463aee2a7bf47619c61517d1db6cef91ac1b60d Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 20 Oct 2026 22:24:31 +0100 Subject: [PATCH 49/51] added a test for empty string.Test failed --- practice-tdd/repeat-str.test.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index ffefe66a9..ac5b193db 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -1,8 +1,6 @@ // Implement a function repeatStr import { repeatStr } from "./repeat-str.js"; - // Case: handle count of 1, 2, 3, 4: - test("should repeat the string 1 times", () => { const str = "hello"; const count = 1; @@ -28,7 +26,6 @@ test("should repeat the string 4 times", () => { expect(repeatedStr).toEqual("hellohellohellohello"); }); // Case: Handle count of 0: - test("should repeat the string 0 times", () => { const str = "hello"; const count = 0; @@ -36,16 +33,16 @@ test("should repeat the string 0 times", () => { expect(repeatedStr).toEqual(""); }); //case: Handle decimal count - test("should repeat the stringthe whole number in the count times", () => { const str = "hello"; const count = 2.5; const repeatedStr = repeatStr(str, count); expect(repeatedStr).toEqual("hellohello"); }); - // Case: Handle negative count: - test("should throw an error when -1 count is given", () => { expect(() => repeatStr("hello", -1)).toThrow("Negative counts are not valid"); }); +test(`should throw an error when string is empty`, () => { + expect(() => repeatStr(" ", 1)).toThrow("String shoild not be empty"); +}); From 08dccc1f202bb31deb71e59c8762baf8e033c367 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 20 Oct 2026 22:25:15 +0100 Subject: [PATCH 50/51] wrote a test that throws error when string is empty --- practice-tdd/repeat-str.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index eafb444b3..f563fde0b 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -6,6 +6,9 @@ export function repeatStr(str, count) { let repeatedStr = str; count = Math.floor(count); + if (str === " ") { + throw new Error("String shoild not be empty"); + } if (count < 0) { throw new Error("Negative counts are not valid"); } From 9f7796a5c6cc7beddce7b50885cbbe27a6552027 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Tue, 20 Oct 2026 22:30:53 +0100 Subject: [PATCH 51/51] restored all coments as advised --- practice-tdd/repeat-str.test.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index ac5b193db..23138e087 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -1,5 +1,14 @@ // Implement a function repeatStr import { repeatStr } from "./repeat-str.js"; +// Given a target string `str` and a positive integer `count`, +// When the repeatStr function is called with these inputs, +// Then it should: + +// Case: handle multiple repetitions: +// Given a target string `str` and a positive integer `count` greater than 1, +// When the repeatStr function is called with these inputs, +// Then it should return a string that contains the original `str` repeated `count` times. + // Case: handle count of 1, 2, 3, 4: test("should repeat the string 1 times", () => { const str = "hello"; @@ -32,7 +41,7 @@ test("should repeat the string 0 times", () => { const repeatedStr = repeatStr(str, count); expect(repeatedStr).toEqual(""); }); -//case: Handle decimal count +//case: Handle decimal count: test("should repeat the stringthe whole number in the count times", () => { const str = "hello"; const count = 2.5; @@ -40,6 +49,9 @@ test("should repeat the stringthe whole number in the count times", () => { expect(repeatedStr).toEqual("hellohello"); }); // 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 -1 count is given", () => { expect(() => repeatStr("hello", -1)).toThrow("Negative counts are not valid"); });