From 301ea630acfa482fd155e83c79c874c0622a453d Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 28 Sep 2026 14:46:02 +0100 Subject: [PATCH 01/67] List edge cases for test. --- format-clock-edge-cases/timeConverter.test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 88f2af094..485e13c8b 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -9,3 +9,18 @@ test("correctly convert time after 12:00", function(){ test("can correctly convert morning time", function() { assert.equal(formatAs12HourClock("08:00"), "08:00 am"); }); + +/* +Edge cases to be tested. + +1. 00:00 +2. 00:01 +3. 01:00 +4. 09:05 +5. 11:59 +6. 23:59 +7. 12:00 +8. 12:01 +9. 12:59 +10.13:00 +*/ \ No newline at end of file From 2501561c60d5751117e7f4369848fcd7c950ceac Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 28 Sep 2026 20:12:24 +0100 Subject: [PATCH 02/67] Update list. --- format-clock-edge-cases/timeConverter.test.js | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 485e13c8b..8003a1feb 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -6,21 +6,26 @@ test("correctly convert time after 12:00", function(){ assert.equal(formatAs12HourClock("23:00"), "11:00 pm"); }); -test("can correctly convert morning time", function() { +test("can correctly convert morning time", function(){ assert.equal(formatAs12HourClock("08:00"), "08:00 am"); }); +test("can correctly convert morning time", function (){ + assert.equal(formatAs12HourClock("00:00"), "12:00 am"); +}); + /* Edge cases to be tested. + Input Expected What it tests -1. 00:00 -2. 00:01 -3. 01:00 -4. 09:05 -5. 11:59 -6. 23:59 -7. 12:00 -8. 12:01 -9. 12:59 -10.13:00 +1. 00:00 -> 12:00 am Midnight: hour 0 becomes 12 +2. 00:01 -> 12:01 am Just after midnight, still 12 +3. 01:00 -> 01:00 am First normal morning hour +4. 09:05 -> 09:05 am Leading zeros in hour and minute +5. 11:59 -> 11:59 am Last minute before noon +6. 23:59 -> 11:59 pm Last minute of the day +7. 12:00 -> 12:00 pm Noon: switches to pm, hour stays 12 +8. 12:01 -> 12:01 pm Just after noon, must not become 00 +9. 12:59 -> 12:59 pm Last minute of the noon hour +10.13:00 -> 01:00 pm First hour after noon: 13 - 12, padded */ \ No newline at end of file From 63e477b4d8dc96b53edf7d343581a5d6e223335b Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 28 Sep 2026 20:36:21 +0100 Subject: [PATCH 03/67] Add an if condition to check midnight --- format-clock-edge-cases/timeConverter.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 310c07bd9..ccd71295f 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -1,11 +1,16 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); + const minutes = time.slice(3, 5); + + if (hours === 0) { + return `12:${minutes} AM` + } if (hours > 12) { - return `${hours - 12}:00 pm`; + return `${hours - 12}:${minutes} PM`; } - return `${time} am`; + return `${time} AM`; } export {formatAs12HourClock}; From a8e1b2d657bc6701d1b2662d9d3f378c2921e33c Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 28 Sep 2026 20:37:04 +0100 Subject: [PATCH 04/67] Add another case to test midnight --- format-clock-edge-cases/timeConverter.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 8003a1feb..4bd33a0fe 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -3,15 +3,15 @@ import assert from "node:assert"; import test from "node:test"; test("correctly convert time after 12:00", function(){ - assert.equal(formatAs12HourClock("23:00"), "11:00 pm"); + assert.equal(formatAs12HourClock("23:00"), "11:00 PM"); }); test("can correctly convert morning time", function(){ - assert.equal(formatAs12HourClock("08:00"), "08:00 am"); + assert.equal(formatAs12HourClock("08:00"), "08:00 AM"); }); -test("can correctly convert morning time", function (){ - assert.equal(formatAs12HourClock("00:00"), "12:00 am"); +test("can correctly convert midnight time", function (){ + assert.equal(formatAs12HourClock("00:00"), "12:00 AM"); }); /* From 9e2cef84be358c6b92e7f4fed3918571a0bf23d7 Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 28 Sep 2026 21:05:07 +0100 Subject: [PATCH 05/67] Add test case 00:01 to 12:01 am --- format-clock-edge-cases/timeConverter.test.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 4bd33a0fe..2c21a2e8c 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -2,6 +2,14 @@ import {formatAs12HourClock} from "./timeConverter.js"; import assert from "node:assert"; import test from "node:test"; +test("can correctly convert midnight time", function () { + assert.equal(formatAs12HourClock("00:00"), "12:00 AM"); +}); + +test("can correctly convert just after midnight", function () { + assert.equal(formatAs12HourClock("00:01"), "12:01 AM"); +}); + test("correctly convert time after 12:00", function(){ assert.equal(formatAs12HourClock("23:00"), "11:00 PM"); }); @@ -10,9 +18,7 @@ test("can correctly convert morning time", function(){ assert.equal(formatAs12HourClock("08:00"), "08:00 AM"); }); -test("can correctly convert midnight time", function (){ - assert.equal(formatAs12HourClock("00:00"), "12:00 AM"); -}); + /* Edge cases to be tested. From 2ba2e3421223ea5b7d3424a55b2909c481067ee1 Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 28 Sep 2026 21:05:53 +0100 Subject: [PATCH 06/67] Add condition for checking midday 12 pm --- format-clock-edge-cases/timeConverter.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index ccd71295f..0e9e5dc92 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -6,7 +6,9 @@ function formatAs12HourClock(time) { if (hours === 0) { return `12:${minutes} AM` } - + if (hours === 12) { + return `12:${minutes} PM`; + } if (hours > 12) { return `${hours - 12}:${minutes} PM`; } From 06d5f9196609421da4bfad96d57138dc34a5f1d5 Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 28 Sep 2026 21:08:52 +0100 Subject: [PATCH 07/67] Add test case for 01:00 to 01:00 am --- format-clock-edge-cases/timeConverter.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 2c21a2e8c..89d71751f 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -10,6 +10,11 @@ test("can correctly convert just after midnight", function () { assert.equal(formatAs12HourClock("00:01"), "12:01 AM"); }); +test("can correctly convert first normal hour", function () { + assert.equal(formatAs12HourClock("01:00"), "01:00 AM"); +}); + + test("correctly convert time after 12:00", function(){ assert.equal(formatAs12HourClock("23:00"), "11:00 PM"); }); From 3dc6da6c1f66800bbf9ad12ded58c2f35c074fb7 Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 28 Sep 2026 21:12:29 +0100 Subject: [PATCH 08/67] Add test case for 11:59 to 11:59 am --- format-clock-edge-cases/timeConverter.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 89d71751f..181110f5d 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -14,6 +14,13 @@ test("can correctly convert first normal hour", function () { assert.equal(formatAs12HourClock("01:00"), "01:00 AM"); }); +test("can correctly convert leading zeros in hour and minute", function () { + assert.equal(formatAs12HourClock("09:05"), "09:05 AM"); +}); + +test("can correctly convert last minute before noon", function () { + assert.equal(formatAs12HourClock("11:59"), "11:59 AM"); +}); test("correctly convert time after 12:00", function(){ assert.equal(formatAs12HourClock("23:00"), "11:00 PM"); From 1e6cb55cff9ebed1dba684a035546a3bf2e73b1a Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 28 Sep 2026 21:20:54 +0100 Subject: [PATCH 09/67] Add test case for 12:01 to 12:01 pm --- format-clock-edge-cases/timeConverter.test.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 181110f5d..a40314267 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -14,6 +14,10 @@ test("can correctly convert first normal hour", function () { assert.equal(formatAs12HourClock("01:00"), "01:00 AM"); }); +test("can correctly convert morning time", function () { + assert.equal(formatAs12HourClock("08:00"), "08:00 AM"); +}); + test("can correctly convert leading zeros in hour and minute", function () { assert.equal(formatAs12HourClock("09:05"), "09:05 AM"); }); @@ -22,13 +26,19 @@ test("can correctly convert last minute before noon", function () { assert.equal(formatAs12HourClock("11:59"), "11:59 AM"); }); +test("can correctly convert time to PM noon", function () { + assert.equal(formatAs12HourClock("12:00"), "12:00 PM"); +}); + +test("can correctly convert time just afternoon", function () { + assert.equal(formatAs12HourClock("12:01"), "12:01 PM"); +}); + test("correctly convert time after 12:00", function(){ assert.equal(formatAs12HourClock("23:00"), "11:00 PM"); }); -test("can correctly convert morning time", function(){ - assert.equal(formatAs12HourClock("08:00"), "08:00 AM"); -}); + @@ -41,9 +51,10 @@ Edge cases to be tested. 3. 01:00 -> 01:00 am First normal morning hour 4. 09:05 -> 09:05 am Leading zeros in hour and minute 5. 11:59 -> 11:59 am Last minute before noon -6. 23:59 -> 11:59 pm Last minute of the day + 7. 12:00 -> 12:00 pm Noon: switches to pm, hour stays 12 8. 12:01 -> 12:01 pm Just after noon, must not become 00 9. 12:59 -> 12:59 pm Last minute of the noon hour 10.13:00 -> 01:00 pm First hour after noon: 13 - 12, padded +6. 23:59 -> 11:59 pm Last minute of the day */ \ No newline at end of file From 61b2ce70c7cb54298572a6b4dab7cb03c596dcaf Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 28 Sep 2026 21:25:30 +0100 Subject: [PATCH 10/67] Add test case for 13:00 to 1:00 pm --- format-clock-edge-cases/timeConverter.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index a40314267..fbf92b1da 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -34,6 +34,14 @@ test("can correctly convert time just afternoon", function () { assert.equal(formatAs12HourClock("12:01"), "12:01 PM"); }); +test("can correctly convert time last minute of the noon hour", function () { + assert.equal(formatAs12HourClock("12:59"), "12:59 PM"); +}); + +test("can correctly convert time first hour after noon", function () { + assert.equal(formatAs12HourClock("13:00"), "1:00 PM"); +}); + test("correctly convert time after 12:00", function(){ assert.equal(formatAs12HourClock("23:00"), "11:00 PM"); }); From 040786906e6dd059ad1748bb69e7559d30acac80 Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 28 Sep 2026 21:28:50 +0100 Subject: [PATCH 11/67] Add test case fo 23:59 to 11:59 pm --- format-clock-edge-cases/timeConverter.test.js | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index fbf92b1da..ffedaea52 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -1,4 +1,4 @@ -import {formatAs12HourClock} from "./timeConverter.js"; +import { formatAs12HourClock } from "./timeConverter.js"; import assert from "node:assert"; import test from "node:test"; @@ -42,13 +42,13 @@ test("can correctly convert time first hour after noon", function () { assert.equal(formatAs12HourClock("13:00"), "1:00 PM"); }); -test("correctly convert time after 12:00", function(){ - assert.equal(formatAs12HourClock("23:00"), "11:00 PM"); +test("correctly convert time after 12:00", function () { + assert.equal(formatAs12HourClock("23:00"), "11:00 PM"); }); - - - +test("can correctly convert time last minute of the day", function () { + assert.equal(formatAs12HourClock("23:59"), "11:59 PM"); +}); /* Edge cases to be tested. @@ -59,10 +59,9 @@ Edge cases to be tested. 3. 01:00 -> 01:00 am First normal morning hour 4. 09:05 -> 09:05 am Leading zeros in hour and minute 5. 11:59 -> 11:59 am Last minute before noon - -7. 12:00 -> 12:00 pm Noon: switches to pm, hour stays 12 -8. 12:01 -> 12:01 pm Just after noon, must not become 00 -9. 12:59 -> 12:59 pm Last minute of the noon hour -10.13:00 -> 01:00 pm First hour after noon: 13 - 12, padded -6. 23:59 -> 11:59 pm Last minute of the day -*/ \ No newline at end of file +6. 12:00 -> 12:00 pm Noon: switches to pm, hour stays 12 +7. 12:01 -> 12:01 pm Just after noon, must not become 00 +8. 12:59 -> 12:59 pm Last minute of the noon hour +9. 13:00 -> 01:00 pm First hour after noon: 13 - 12, padded +10.23:59 -> 11:59 pm Last minute of the day +*/ From 06d3f9a0c6958076566110dae7ed8b1265059d31 Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 28 Sep 2026 21:36:26 +0100 Subject: [PATCH 12/67] Add padStart method to hours --- format-clock-edge-cases/timeConverter.js | 2 +- format-clock-edge-cases/timeConverter.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 0e9e5dc92..9703a7fea 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -1,6 +1,6 @@ function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); + const hours = Number(time.slice(0, 2).padStart(2, 0)); const minutes = time.slice(3, 5); if (hours === 0) { diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index ffedaea52..1803282b5 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -39,7 +39,7 @@ test("can correctly convert time last minute of the noon hour", function () { }); test("can correctly convert time first hour after noon", function () { - assert.equal(formatAs12HourClock("13:00"), "1:00 PM"); + assert.equal(formatAs12HourClock("13:00"), "01:00 PM"); }); test("correctly convert time after 12:00", function () { From 598f744790e7497234e6b954abc127e280707755 Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 28 Sep 2026 21:42:18 +0100 Subject: [PATCH 13/67] Add more description. --- format-clock-edge-cases/timeConverter.test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 1803282b5..f3ffcea1e 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -2,15 +2,15 @@ import { formatAs12HourClock } from "./timeConverter.js"; import assert from "node:assert"; import test from "node:test"; -test("can correctly convert midnight time", function () { +test("can correctly convert time at midnight ", function () { assert.equal(formatAs12HourClock("00:00"), "12:00 AM"); }); -test("can correctly convert just after midnight", function () { +test("can correctly convert time just after midnight", function () { assert.equal(formatAs12HourClock("00:01"), "12:01 AM"); }); -test("can correctly convert first normal hour", function () { +test("can correctly convert time at the first normal hour", function () { assert.equal(formatAs12HourClock("01:00"), "01:00 AM"); }); @@ -18,15 +18,15 @@ test("can correctly convert morning time", function () { assert.equal(formatAs12HourClock("08:00"), "08:00 AM"); }); -test("can correctly convert leading zeros in hour and minute", function () { +test("can correctly convert time on leading zeros in hour and minute", function () { assert.equal(formatAs12HourClock("09:05"), "09:05 AM"); }); -test("can correctly convert last minute before noon", function () { +test("can correctly convert time just last minute before noon", function () { assert.equal(formatAs12HourClock("11:59"), "11:59 AM"); }); -test("can correctly convert time to PM noon", function () { +test("can correctly convert time to PM at noon", function () { assert.equal(formatAs12HourClock("12:00"), "12:00 PM"); }); From e6fde3bd32233e9e618bc5ad607ef8182ed4337c Mon Sep 17 00:00:00 2001 From: russom Date: Tue, 29 Sep 2026 22:31:32 +0100 Subject: [PATCH 14/67] Add padStart method to convert 23:00 to 01:00pm --- format-clock-edge-cases/timeConverter.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 9703a7fea..489779331 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -1,18 +1,19 @@ function formatAs12HourClock(time) { + const hours = Number(time.slice(0, 2)); - const hours = Number(time.slice(0, 2).padStart(2, 0)); const minutes = time.slice(3, 5); if (hours === 0) { - return `12:${minutes} AM` + return `12:${minutes} AM`; } if (hours === 12) { return `12:${minutes} PM`; } if (hours > 12) { - return `${hours - 12}:${minutes} PM`; + const paddedHours = String(hours - 12).padStart(2, "0"); + return `${paddedHours}:${minutes} PM`; } return `${time} AM`; } -export {formatAs12HourClock}; +export { formatAs12HourClock }; From c2f743cc9af42331cdaf0ed8e70d589b6d160355 Mon Sep 17 00:00:00 2001 From: russom Date: Tue, 29 Sep 2026 22:34:46 +0100 Subject: [PATCH 15/67] Edit comments --- format-clock-edge-cases/timeConverter.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index f3ffcea1e..5208d6384 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -53,7 +53,6 @@ test("can correctly convert time last minute of the day", function () { /* Edge cases to be tested. Input Expected What it tests - 1. 00:00 -> 12:00 am Midnight: hour 0 becomes 12 2. 00:01 -> 12:01 am Just after midnight, still 12 3. 01:00 -> 01:00 am First normal morning hour From e7ff9c7e7aeb92a258a202676cb92762eee1ec71 Mon Sep 17 00:00:00 2001 From: russom Date: Wed, 30 Sep 2026 13:09:10 +0100 Subject: [PATCH 16/67] Inline code directly into return statement --- format-clock-edge-cases/timeConverter.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 489779331..a784d125f 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -10,8 +10,7 @@ function formatAs12HourClock(time) { return `12:${minutes} PM`; } if (hours > 12) { - const paddedHours = String(hours - 12).padStart(2, "0"); - return `${paddedHours}:${minutes} PM`; + return `${String(hours - 12).padStart(2, "0")}:${minutes} PM`; } return `${time} AM`; } From 751fb787e8c9314b5ce60dbce71399fc6cdc5110 Mon Sep 17 00:00:00 2001 From: russom Date: Wed, 30 Sep 2026 20:55:15 +0100 Subject: [PATCH 17/67] Change am and pm to lower case and update description. --- format-clock-edge-cases/timeConverter.js | 8 ++-- format-clock-edge-cases/timeConverter.test.js | 38 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index a784d125f..192894d77 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -4,15 +4,15 @@ function formatAs12HourClock(time) { const minutes = time.slice(3, 5); if (hours === 0) { - return `12:${minutes} AM`; + return `12:${minutes} am`; } if (hours === 12) { - return `12:${minutes} PM`; + return `12:${minutes} pm`; } if (hours > 12) { - return `${String(hours - 12).padStart(2, "0")}:${minutes} PM`; + return `${String(hours - 12).padStart(2, "0")}:${minutes} pm`; } - return `${time} AM`; + return `${time} am`; } export { formatAs12HourClock }; diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 5208d6384..8889b2c7b 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -2,52 +2,52 @@ import { formatAs12HourClock } from "./timeConverter.js"; import assert from "node:assert"; import test from "node:test"; +test("can correctly convert time last minute of the day", function () { + assert.equal(formatAs12HourClock("23:59"), "11:59 pm"); +}); + +test("can correctly convert morning time", function () { + assert.equal(formatAs12HourClock("08:00"), "08:00 am"); +}); + test("can correctly convert time at midnight ", function () { - assert.equal(formatAs12HourClock("00:00"), "12:00 AM"); + assert.equal(formatAs12HourClock("00:00"), "12:00 am"); }); test("can correctly convert time just after midnight", function () { - assert.equal(formatAs12HourClock("00:01"), "12:01 AM"); + assert.equal(formatAs12HourClock("00:01"), "12:01 am"); }); test("can correctly convert time at the first normal hour", function () { - assert.equal(formatAs12HourClock("01:00"), "01:00 AM"); -}); - -test("can correctly convert morning time", function () { - assert.equal(formatAs12HourClock("08:00"), "08:00 AM"); + assert.equal(formatAs12HourClock("01:00"), "01:00 am"); }); test("can correctly convert time on leading zeros in hour and minute", function () { - assert.equal(formatAs12HourClock("09:05"), "09:05 AM"); + assert.equal(formatAs12HourClock("09:05"), "09:05 am"); }); test("can correctly convert time just last minute before noon", function () { - assert.equal(formatAs12HourClock("11:59"), "11:59 AM"); + assert.equal(formatAs12HourClock("11:59"), "11:59 am"); }); test("can correctly convert time to PM at noon", function () { - assert.equal(formatAs12HourClock("12:00"), "12:00 PM"); + assert.equal(formatAs12HourClock("12:00"), "12:00 pm"); }); test("can correctly convert time just afternoon", function () { - assert.equal(formatAs12HourClock("12:01"), "12:01 PM"); + assert.equal(formatAs12HourClock("12:01"), "12:01 pm"); }); test("can correctly convert time last minute of the noon hour", function () { - assert.equal(formatAs12HourClock("12:59"), "12:59 PM"); + assert.equal(formatAs12HourClock("12:59"), "12:59 pm"); }); test("can correctly convert time first hour after noon", function () { - assert.equal(formatAs12HourClock("13:00"), "01:00 PM"); + assert.equal(formatAs12HourClock("13:00"), "01:00 pm"); }); -test("correctly convert time after 12:00", function () { - assert.equal(formatAs12HourClock("23:00"), "11:00 PM"); -}); - -test("can correctly convert time last minute of the day", function () { - assert.equal(formatAs12HourClock("23:59"), "11:59 PM"); +test("correctly convert time before midnight", function () { + assert.equal(formatAs12HourClock("23:00"), "11:00 pm"); }); /* From 4707f5ae5a5fca7ca09a839f25a09747f8dd9f52 Mon Sep 17 00:00:00 2001 From: russom Date: Wed, 30 Sep 2026 21:17:03 +0100 Subject: [PATCH 18/67] Unreachable code. --- dead-code/exercise-1.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dead-code/exercise-1.js b/dead-code/exercise-1.js index 4d09f15fa..e5ab68be2 100644 --- a/dead-code/exercise-1.js +++ b/dead-code/exercise-1.js @@ -5,9 +5,9 @@ let testName = "Jerry"; const greeting = "hello"; function sayHello(greeting, name) { - const greetingStr = greeting + ", " + name + "!"; + return `${greeting}, ${name}!`; - console.log(greetingStr); + } testName = "Aman"; From f504687afc5ffe3be7784d73a30092d19e906211 Mon Sep 17 00:00:00 2001 From: russom Date: Wed, 30 Sep 2026 21:27:07 +0100 Subject: [PATCH 19/67] Remove unreachable and redundant code. --- dead-code/exercise-1.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/dead-code/exercise-1.js b/dead-code/exercise-1.js index e5ab68be2..5593f9e23 100644 --- a/dead-code/exercise-1.js +++ b/dead-code/exercise-1.js @@ -1,17 +1,6 @@ // Find the instances of unreachable and redundant code - remove them! // The sayHello function should continue to work for any reasonable input it's given. -let testName = "Jerry"; -const greeting = "hello"; - function sayHello(greeting, name) { - return `${greeting}, ${name}!`; - } - -testName = "Aman"; - -const greetingMessage = sayHello(greeting, testName); - -console.log(greetingMessage); // 'hello, Aman!' From d9197c47e1591171187d6fbd063620cf80aed368 Mon Sep 17 00:00:00 2001 From: russom Date: Wed, 30 Sep 2026 22:39:13 +0100 Subject: [PATCH 20/67] Remove unused code --- dead-code/exercise-2.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/dead-code/exercise-2.js b/dead-code/exercise-2.js index 56d7887c4..3b7d2e0f7 100644 --- a/dead-code/exercise-2.js +++ b/dead-code/exercise-2.js @@ -2,27 +2,21 @@ // The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; -const capitalisedPets = pets.map((pet) => pet.toUpperCase()); -const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); - -function logPets(petsArr) { - petsArr.forEach((pet) => console.log(pet)); -} function countAndCapitalisePets(petsArr) { const petCount = {}; - petsArr.forEach((pet) => { - const capitalisedPet = pet.toUpperCase(); + petsArr.filter((pet) => pet[0] === "h").forEach((pet) => { + const capitalisedPet = pet.toUpperCase() + if (petCount[capitalisedPet]) { petCount[capitalisedPet] += 1; } else { petCount[capitalisedPet] = 1; } }); + return petCount; } -const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH); - -console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log +console.log(countAndCapitalisePets(pets)); \ No newline at end of file From 9494c3dac2547134a695d9155abb492e162abeca Mon Sep 17 00:00:00 2001 From: russom Date: Wed, 30 Sep 2026 22:42:16 +0100 Subject: [PATCH 21/67] Update function to work for any input. --- dead-code/exercise-2.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dead-code/exercise-2.js b/dead-code/exercise-2.js index 3b7d2e0f7..e57e5f190 100644 --- a/dead-code/exercise-2.js +++ b/dead-code/exercise-2.js @@ -19,4 +19,5 @@ function countAndCapitalisePets(petsArr) { return petCount; } -console.log(countAndCapitalisePets(pets)); \ No newline at end of file +const animals = ["lion", "hyena", "elephant", "hippo", "tiger", "hippo"] +console.log(countAndCapitalisePets(animals)); \ No newline at end of file From 582699c1261356f84c8a4b911feb23d3704cca8d Mon Sep 17 00:00:00 2001 From: russom Date: Wed, 30 Sep 2026 22:45:05 +0100 Subject: [PATCH 22/67] Format code with prettier. --- dead-code/exercise-2.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/dead-code/exercise-2.js b/dead-code/exercise-2.js index e57e5f190..16ca0657e 100644 --- a/dead-code/exercise-2.js +++ b/dead-code/exercise-2.js @@ -6,18 +6,20 @@ const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; function countAndCapitalisePets(petsArr) { const petCount = {}; - petsArr.filter((pet) => pet[0] === "h").forEach((pet) => { - const capitalisedPet = pet.toUpperCase() + petsArr + .filter((pet) => pet[0] === "h") + .forEach((pet) => { + const capitalisedPet = pet.toUpperCase(); + + if (petCount[capitalisedPet]) { + petCount[capitalisedPet] += 1; + } else { + petCount[capitalisedPet] = 1; + } + }); - if (petCount[capitalisedPet]) { - petCount[capitalisedPet] += 1; - } else { - petCount[capitalisedPet] = 1; - } - }); - return petCount; } -const animals = ["lion", "hyena", "elephant", "hippo", "tiger", "hippo"] -console.log(countAndCapitalisePets(animals)); \ No newline at end of file +const animals = ["lion", "hyena", "elephant", "hippo", "tiger", "hippo"]; +console.log(countAndCapitalisePets(animals)); From b806b4115e598a01afb8fcb0ad36ea8cc1f484bd Mon Sep 17 00:00:00 2001 From: russom Date: Sat, 3 Oct 2026 15:13:24 +0100 Subject: [PATCH 23/67] Stop tracking files --- format-clock-edge-cases/timeConverter.js | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 format-clock-edge-cases/timeConverter.js diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js deleted file mode 100644 index 192894d77..000000000 --- a/format-clock-edge-cases/timeConverter.js +++ /dev/null @@ -1,18 +0,0 @@ -function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); - - const minutes = time.slice(3, 5); - - if (hours === 0) { - return `12:${minutes} am`; - } - if (hours === 12) { - return `12:${minutes} pm`; - } - if (hours > 12) { - return `${String(hours - 12).padStart(2, "0")}:${minutes} pm`; - } - return `${time} am`; -} - -export { formatAs12HourClock }; From fcf27e7360b9d8f4c9b6dc2148792d6c97f1798a Mon Sep 17 00:00:00 2001 From: russom Date: Sat, 3 Oct 2026 15:14:57 +0100 Subject: [PATCH 24/67] Stop tracking files --- format-clock-edge-cases/timeConverter.test.js | 66 ------------------- 1 file changed, 66 deletions(-) delete mode 100644 format-clock-edge-cases/timeConverter.test.js diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js deleted file mode 100644 index 8889b2c7b..000000000 --- a/format-clock-edge-cases/timeConverter.test.js +++ /dev/null @@ -1,66 +0,0 @@ -import { formatAs12HourClock } from "./timeConverter.js"; -import assert from "node:assert"; -import test from "node:test"; - -test("can correctly convert time last minute of the day", function () { - assert.equal(formatAs12HourClock("23:59"), "11:59 pm"); -}); - -test("can correctly convert morning time", function () { - assert.equal(formatAs12HourClock("08:00"), "08:00 am"); -}); - -test("can correctly convert time at midnight ", function () { - assert.equal(formatAs12HourClock("00:00"), "12:00 am"); -}); - -test("can correctly convert time just after midnight", function () { - assert.equal(formatAs12HourClock("00:01"), "12:01 am"); -}); - -test("can correctly convert time at the first normal hour", function () { - assert.equal(formatAs12HourClock("01:00"), "01:00 am"); -}); - -test("can correctly convert time on leading zeros in hour and minute", function () { - assert.equal(formatAs12HourClock("09:05"), "09:05 am"); -}); - -test("can correctly convert time just last minute before noon", function () { - assert.equal(formatAs12HourClock("11:59"), "11:59 am"); -}); - -test("can correctly convert time to PM at noon", function () { - assert.equal(formatAs12HourClock("12:00"), "12:00 pm"); -}); - -test("can correctly convert time just afternoon", function () { - assert.equal(formatAs12HourClock("12:01"), "12:01 pm"); -}); - -test("can correctly convert time last minute of the noon hour", function () { - assert.equal(formatAs12HourClock("12:59"), "12:59 pm"); -}); - -test("can correctly convert time first hour after noon", function () { - assert.equal(formatAs12HourClock("13:00"), "01:00 pm"); -}); - -test("correctly convert time before midnight", function () { - assert.equal(formatAs12HourClock("23:00"), "11:00 pm"); -}); - -/* -Edge cases to be tested. - Input Expected What it tests -1. 00:00 -> 12:00 am Midnight: hour 0 becomes 12 -2. 00:01 -> 12:01 am Just after midnight, still 12 -3. 01:00 -> 01:00 am First normal morning hour -4. 09:05 -> 09:05 am Leading zeros in hour and minute -5. 11:59 -> 11:59 am Last minute before noon -6. 12:00 -> 12:00 pm Noon: switches to pm, hour stays 12 -7. 12:01 -> 12:01 pm Just after noon, must not become 00 -8. 12:59 -> 12:59 pm Last minute of the noon hour -9. 13:00 -> 01:00 pm First hour after noon: 13 - 12, padded -10.23:59 -> 11:59 pm Last minute of the day -*/ From 04f544f7feca8b80b84cca68cba73dd53144b58f Mon Sep 17 00:00:00 2001 From: russom Date: Sat, 3 Oct 2026 15:55:44 +0100 Subject: [PATCH 25/67] Restore files unrelated to this PR --- format-clock-edge-cases/timeConverter.js | 11 +++++++++++ format-clock-edge-cases/timeConverter.test.js | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 format-clock-edge-cases/timeConverter.js create mode 100644 format-clock-edge-cases/timeConverter.test.js diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js new file mode 100644 index 000000000..310c07bd9 --- /dev/null +++ b/format-clock-edge-cases/timeConverter.js @@ -0,0 +1,11 @@ +function formatAs12HourClock(time) { + + const hours = Number(time.slice(0, 2)); + + if (hours > 12) { + return `${hours - 12}:00 pm`; + } + return `${time} am`; +} + +export {formatAs12HourClock}; diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js new file mode 100644 index 000000000..88f2af094 --- /dev/null +++ b/format-clock-edge-cases/timeConverter.test.js @@ -0,0 +1,11 @@ +import {formatAs12HourClock} from "./timeConverter.js"; +import assert from "node:assert"; +import test from "node:test"; + +test("correctly convert time after 12:00", function(){ + assert.equal(formatAs12HourClock("23:00"), "11:00 pm"); +}); + +test("can correctly convert morning time", function() { + assert.equal(formatAs12HourClock("08:00"), "08:00 am"); +}); From 4815e87568540639e435716e3aad0986644faa7c Mon Sep 17 00:00:00 2001 From: russom Date: Sat, 3 Oct 2026 16:35:58 +0100 Subject: [PATCH 26/67] Add if condition for checking right angle. --- implement-and-rewrite-tests/implement/1-get-angle-type.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/implement-and-rewrite-tests/implement/1-get-angle-type.js b/implement-and-rewrite-tests/implement/1-get-angle-type.js index 8a6fba050..3ba549bbb 100644 --- a/implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -18,4 +18,7 @@ export function getAngleType(angle) { // TODO: Implement this function + if (angle === 90) { + return "Right angle"; + } } From 9dc9e1ffb91a6e07a9ff4163b2c9533aee4c984b Mon Sep 17 00:00:00 2001 From: russom Date: Sat, 3 Oct 2026 22:16:49 +0100 Subject: [PATCH 27/67] Write test for Acute angle. --- .../implement-tests-with-node-test/1-get-angle-type.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js index cf50f6cad..30da8da07 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js @@ -10,3 +10,8 @@ test("Classifies right angles", () => { const right = getAngleType(90); assert.equal(right, "Right angle"); }); + +test("Classifies Acute angles", () => { + const Acute = getAngleType(90); + assert.equal(Acute, "Acute angle"); +}); \ No newline at end of file From 10b0d0f4ffb61973fad4d4a33c58981f7a26ab6c Mon Sep 17 00:00:00 2001 From: russom Date: Sat, 3 Oct 2026 22:20:12 +0100 Subject: [PATCH 28/67] Write test for Obtuse angle. --- .../1-get-angle-type.test.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js index 30da8da07..464f16e9a 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js @@ -6,12 +6,18 @@ import { getAngleType } from "../implement/1-get-angle-type.js"; // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles +test("Classifies Acute angles", () => { + const Acute = getAngleType(89); + assert.equal(Acute, "Acute angle"); +}); + test("Classifies right angles", () => { const right = getAngleType(90); assert.equal(right, "Right angle"); }); -test("Classifies Acute angles", () => { - const Acute = getAngleType(90); - assert.equal(Acute, "Acute angle"); -}); \ No newline at end of file +test("Classifies Obtuse angles", () => { + const Obtuse = getAngleType(89); + assert.equal(Obtuse, "Obtuse angle"); +}); + From cccf002bfc2928a46bbac1fc98694c3f01c90547 Mon Sep 17 00:00:00 2001 From: russom Date: Sat, 3 Oct 2026 22:21:00 +0100 Subject: [PATCH 29/67] Add if condition for checking Acute angle. --- implement-and-rewrite-tests/implement/1-get-angle-type.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/implement-and-rewrite-tests/implement/1-get-angle-type.js b/implement-and-rewrite-tests/implement/1-get-angle-type.js index 3ba549bbb..05314ff66 100644 --- a/implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -18,7 +18,10 @@ export function getAngleType(angle) { // TODO: Implement this function - if (angle === 90) { + if (angle > 0 && angle < 90) { + return "Acute angle" + } + else if (angle === 90) { return "Right angle"; } } From ed2729e307da4ebe3c498d745cf50eb18706e20b Mon Sep 17 00:00:00 2001 From: russom Date: Sat, 3 Oct 2026 22:25:37 +0100 Subject: [PATCH 30/67] Add if condition for checking Obtuse angle. --- implement-and-rewrite-tests/implement/1-get-angle-type.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/implement-and-rewrite-tests/implement/1-get-angle-type.js b/implement-and-rewrite-tests/implement/1-get-angle-type.js index 05314ff66..087a70692 100644 --- a/implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -19,9 +19,11 @@ export function getAngleType(angle) { // TODO: Implement this function if (angle > 0 && angle < 90) { - return "Acute angle" - } - else if (angle === 90) { + return "Acute angle"; + } else if (angle === 90) { return "Right angle"; + } else if (angle > 90 && angle < 180) { + return "Obtuse angle"; } + } From 4fa3e6cf79af16eca1e792f337f34293aa2f9efd Mon Sep 17 00:00:00 2001 From: russom Date: Sat, 3 Oct 2026 22:31:33 +0100 Subject: [PATCH 31/67] Write test for invalid angles --- .../1-get-angle-type.test.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js index 464f16e9a..6cdb02a83 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js @@ -17,7 +17,21 @@ test("Classifies right angles", () => { }); test("Classifies Obtuse angles", () => { - const Obtuse = getAngleType(89); + const Obtuse = getAngleType(99); assert.equal(Obtuse, "Obtuse angle"); }); +test("Classifies Straight angles", () => { + const Straight = getAngleType(180); + assert.equal(Straight, "Straight angle"); +}); + +test("Classifies Reflex angles", () => { + const Reflex = getAngleType(181); + assert.equal(Reflex, "Reflex angle"); +}); + +test("Classifies Invalid angles", () => { + const Invalid = getAngleType(399); + assert.equal(Invalid, "Invalid angle"); +}); \ No newline at end of file From ea5fa0f2e9de0c6cd8fd7b1d7e4ecfe9704e3784 Mon Sep 17 00:00:00 2001 From: russom Date: Sat, 3 Oct 2026 22:31:56 +0100 Subject: [PATCH 32/67] Add final if condition for checking invalid angle --- implement-and-rewrite-tests/implement/1-get-angle-type.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/implement-and-rewrite-tests/implement/1-get-angle-type.js b/implement-and-rewrite-tests/implement/1-get-angle-type.js index 087a70692..bf7490771 100644 --- a/implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -24,6 +24,12 @@ export function getAngleType(angle) { return "Right angle"; } else if (angle > 90 && angle < 180) { return "Obtuse angle"; + } else if (angle === 180) { + return "Straight angle"; + } else if (angle > 180 && angle < 360) { + return "Reflex angle"; + } else { + return "Invalid angle" } } From 6102a89e716adc450cd2b91056e284a21d3a8af0 Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 4 Oct 2026 21:31:13 +0100 Subject: [PATCH 33/67] Add boundary case test for acute angle. --- .../1-get-angle-type.test.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js index 6cdb02a83..5b5b93c0d 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js @@ -7,12 +7,18 @@ import { getAngleType } from "../implement/1-get-angle-type.js"; // Example: Identify Right Angles test("Classifies Acute angles", () => { - const Acute = getAngleType(89); + const Acute = getAngleType(1); assert.equal(Acute, "Acute angle"); + + const Acute1 = getAngleType(45); + assert.equal(Acute1, "Acute angle"); + + const Acute2 = getAngleType(89); + assert.equal(Acute2, "Acute angle"); }); test("Classifies right angles", () => { - const right = getAngleType(90); + const right = getAngleType(90, ); assert.equal(right, "Right angle"); }); From 717584dcb37b70d2cde34bb8520f7386e874f25c Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 4 Oct 2026 21:32:10 +0100 Subject: [PATCH 34/67] Add if condition for checking invalid inputs. --- implement-and-rewrite-tests/implement/1-get-angle-type.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/implement-and-rewrite-tests/implement/1-get-angle-type.js b/implement-and-rewrite-tests/implement/1-get-angle-type.js index bf7490771..6255e3400 100644 --- a/implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -29,7 +29,6 @@ export function getAngleType(angle) { } else if (angle > 180 && angle < 360) { return "Reflex angle"; } else { - return "Invalid angle" + return "Invalid angle"; } - } From fed8ddd8019712ad1aecb8859cba0e6e1edda2a2 Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 4 Oct 2026 21:44:21 +0100 Subject: [PATCH 35/67] Add boundary test cases for multiple angles. --- .../1-get-angle-type.test.js | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js index 5b5b93c0d..89bb57d9b 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js @@ -18,13 +18,19 @@ test("Classifies Acute angles", () => { }); test("Classifies right angles", () => { - const right = getAngleType(90, ); + const right = getAngleType(90); assert.equal(right, "Right angle"); }); test("Classifies Obtuse angles", () => { - const Obtuse = getAngleType(99); + const Obtuse = getAngleType(91); assert.equal(Obtuse, "Obtuse angle"); + + const Obtuse1 = getAngleType(120); + assert.equal(Obtuse1, "Obtuse angle"); + + const Obtuse2 = getAngleType(179); + assert.equal(Obtuse2, "Obtuse angle"); }); test("Classifies Straight angles", () => { @@ -35,9 +41,27 @@ test("Classifies Straight angles", () => { test("Classifies Reflex angles", () => { const Reflex = getAngleType(181); assert.equal(Reflex, "Reflex angle"); + + const Reflex1 = getAngleType(299); + assert.equal(Reflex1, "Reflex angle"); + + const Reflex2 = getAngleType(360); + assert.equal(Reflex2, "Reflex angle"); }); test("Classifies Invalid angles", () => { - const Invalid = getAngleType(399); + const Invalid = getAngleType(0); assert.equal(Invalid, "Invalid angle"); -}); \ No newline at end of file + + const Invalid1 = getAngleType(361); + assert.equal(Invalid1, "Invalid angle"); + + const Invalid2 = getAngleType(399); + assert.equal(Invalid2, "Invalid angle"); + + const Invalid3 = getAngleType(-7); + assert.equal(Invalid3, "Invalid angle"); + + const Invalid4 = getAngleType(30.2); + assert.equal(Invalid4, "Invalid angle"); +}); From bb815ef5de66e609a0cc7720eb073a919d15cdf1 Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 4 Oct 2026 21:45:16 +0100 Subject: [PATCH 36/67] Add = operator for checking 360 degrees is included --- implement-and-rewrite-tests/implement/1-get-angle-type.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/implement-and-rewrite-tests/implement/1-get-angle-type.js b/implement-and-rewrite-tests/implement/1-get-angle-type.js index 6255e3400..e10c0d61d 100644 --- a/implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -26,7 +26,7 @@ export function getAngleType(angle) { return "Obtuse angle"; } else if (angle === 180) { return "Straight angle"; - } else if (angle > 180 && angle < 360) { + } else if (angle > 180 && angle <= 360) { return "Reflex angle"; } else { return "Invalid angle"; From c8fc9dd540dfcfecbe467d3732d3d290bff2992f Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 5 Oct 2026 14:36:40 +0100 Subject: [PATCH 37/67] Add boundary test cases. --- .../1-get-angle-type.test.js | 55 ------------------- 1 file changed, 55 deletions(-) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js index 89bb57d9b..cf50f6cad 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js @@ -6,62 +6,7 @@ import { getAngleType } from "../implement/1-get-angle-type.js"; // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles -test("Classifies Acute angles", () => { - const Acute = getAngleType(1); - assert.equal(Acute, "Acute angle"); - - const Acute1 = getAngleType(45); - assert.equal(Acute1, "Acute angle"); - - const Acute2 = getAngleType(89); - assert.equal(Acute2, "Acute angle"); -}); - test("Classifies right angles", () => { const right = getAngleType(90); assert.equal(right, "Right angle"); }); - -test("Classifies Obtuse angles", () => { - const Obtuse = getAngleType(91); - assert.equal(Obtuse, "Obtuse angle"); - - const Obtuse1 = getAngleType(120); - assert.equal(Obtuse1, "Obtuse angle"); - - const Obtuse2 = getAngleType(179); - assert.equal(Obtuse2, "Obtuse angle"); -}); - -test("Classifies Straight angles", () => { - const Straight = getAngleType(180); - assert.equal(Straight, "Straight angle"); -}); - -test("Classifies Reflex angles", () => { - const Reflex = getAngleType(181); - assert.equal(Reflex, "Reflex angle"); - - const Reflex1 = getAngleType(299); - assert.equal(Reflex1, "Reflex angle"); - - const Reflex2 = getAngleType(360); - assert.equal(Reflex2, "Reflex angle"); -}); - -test("Classifies Invalid angles", () => { - const Invalid = getAngleType(0); - assert.equal(Invalid, "Invalid angle"); - - const Invalid1 = getAngleType(361); - assert.equal(Invalid1, "Invalid angle"); - - const Invalid2 = getAngleType(399); - assert.equal(Invalid2, "Invalid angle"); - - const Invalid3 = getAngleType(-7); - assert.equal(Invalid3, "Invalid angle"); - - const Invalid4 = getAngleType(30.2); - assert.equal(Invalid4, "Invalid angle"); -}); From 3a565e93f8cae9a6e6eff8816cb91bf501df1a97 Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 5 Oct 2026 15:03:11 +0100 Subject: [PATCH 38/67] Add angle type boundary tests --- .../1-get-angle-type.test.js | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js index cf50f6cad..89bb57d9b 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js @@ -6,7 +6,62 @@ import { getAngleType } from "../implement/1-get-angle-type.js"; // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles +test("Classifies Acute angles", () => { + const Acute = getAngleType(1); + assert.equal(Acute, "Acute angle"); + + const Acute1 = getAngleType(45); + assert.equal(Acute1, "Acute angle"); + + const Acute2 = getAngleType(89); + assert.equal(Acute2, "Acute angle"); +}); + test("Classifies right angles", () => { const right = getAngleType(90); assert.equal(right, "Right angle"); }); + +test("Classifies Obtuse angles", () => { + const Obtuse = getAngleType(91); + assert.equal(Obtuse, "Obtuse angle"); + + const Obtuse1 = getAngleType(120); + assert.equal(Obtuse1, "Obtuse angle"); + + const Obtuse2 = getAngleType(179); + assert.equal(Obtuse2, "Obtuse angle"); +}); + +test("Classifies Straight angles", () => { + const Straight = getAngleType(180); + assert.equal(Straight, "Straight angle"); +}); + +test("Classifies Reflex angles", () => { + const Reflex = getAngleType(181); + assert.equal(Reflex, "Reflex angle"); + + const Reflex1 = getAngleType(299); + assert.equal(Reflex1, "Reflex angle"); + + const Reflex2 = getAngleType(360); + assert.equal(Reflex2, "Reflex angle"); +}); + +test("Classifies Invalid angles", () => { + const Invalid = getAngleType(0); + assert.equal(Invalid, "Invalid angle"); + + const Invalid1 = getAngleType(361); + assert.equal(Invalid1, "Invalid angle"); + + const Invalid2 = getAngleType(399); + assert.equal(Invalid2, "Invalid angle"); + + const Invalid3 = getAngleType(-7); + assert.equal(Invalid3, "Invalid angle"); + + const Invalid4 = getAngleType(30.2); + assert.equal(Invalid4, "Invalid angle"); +}); From c80ed87564226f0cc1406e43f8dd4b483fd11097 Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 5 Oct 2026 15:03:44 +0100 Subject: [PATCH 39/67] Add angle type boundary tests --- .../1-get-angle-type.test.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js index 89bb57d9b..2511112a2 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js @@ -42,11 +42,11 @@ test("Classifies Reflex angles", () => { const Reflex = getAngleType(181); assert.equal(Reflex, "Reflex angle"); - const Reflex1 = getAngleType(299); - assert.equal(Reflex1, "Reflex angle"); + const Reflex1 = getAngleType(299); + assert.equal(Reflex1, "Reflex angle"); - const Reflex2 = getAngleType(360); - assert.equal(Reflex2, "Reflex angle"); + const Reflex2 = getAngleType(360); + assert.equal(Reflex2, "Reflex angle"); }); test("Classifies Invalid angles", () => { @@ -59,9 +59,9 @@ test("Classifies Invalid angles", () => { const Invalid2 = getAngleType(399); assert.equal(Invalid2, "Invalid angle"); - const Invalid3 = getAngleType(-7); - assert.equal(Invalid3, "Invalid angle"); + const Invalid3 = getAngleType(-7); + assert.equal(Invalid3, "Invalid angle"); - const Invalid4 = getAngleType(30.2); - assert.equal(Invalid4, "Invalid angle"); + const Invalid4 = getAngleType(30.2); + assert.equal(Invalid4, "Invalid angle"); }); From 38c28b3f07ef62fe03fa5e126cd28a4d4519ed54 Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 5 Oct 2026 15:12:49 +0100 Subject: [PATCH 40/67] Implement if condition to check propr function. --- .../implement/2-is-proper-fraction.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js index f983800f0..a8fcfbbc7 100644 --- a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -15,4 +15,10 @@ export function isProperFraction(numerator, denominator) { // TODO: Implement this function + if (numerator < denominator) { + return true; + } else { + return false; + } } + From f12c63543b74a2e2d94aeee3b61772d1f8eb08e1 Mon Sep 17 00:00:00 2001 From: russom Date: Tue, 6 Oct 2026 10:11:27 +0100 Subject: [PATCH 41/67] Delete not needed test. --- .../implement-tests-with-node-test/1-get-angle-type.test.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js index 2511112a2..4a3d88089 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js @@ -61,7 +61,4 @@ test("Classifies Invalid angles", () => { const Invalid3 = getAngleType(-7); assert.equal(Invalid3, "Invalid angle"); - - const Invalid4 = getAngleType(30.2); - assert.equal(Invalid4, "Invalid angle"); }); From 48b8daea41b4a1fdddeaa62deecbe793e241c5a8 Mon Sep 17 00:00:00 2001 From: russom Date: Tue, 6 Oct 2026 11:00:32 +0100 Subject: [PATCH 42/67] Write cases for testing proper and improper fractions. --- .../2-is-proper-fraction.test.js | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js index a29084605..2eb2ce300 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js @@ -10,3 +10,58 @@ test("Basic proper fraction", () => { // Example: 1/2 is a proper fraction assert.equal(isProperFraction(1, 2), true); }); + +// Proper fraction +test("Decimal proper fraction", () => { + assert.equal(isProperFraction(0.5, 1.5), true); +}); + +test("0 numerator proper fraction", () => { + assert.equal(isProperFraction(0, 5), true); +}); + +test("Negative numerator proper fraction", () => { + assert.equal(isProperFraction(-9, 1), true); +}); + +test("Both negatives proper fraction", () => { + assert.equal(isProperFraction(-7, -3), true); +}); + +test("Large number proper fraction", () => { + assert.equal(isProperFraction(999, 1000), true); +}); + +test("Very small denominator proper fraction", () => { + assert.equal(isProperFraction(1, 1000000), true); +}); + +// Improper fractions + +test("Decimal improper fraction", () => { + assert.equal(isProperFraction(1.2, 1.1), false); +}); + +test("Numerator larger improper fraction", () => { + assert.equal(isProperFraction(5, 3), false); +}); + +test("Both equal improper fraction", () => { + assert.equal(isProperFraction(4, 4), false); +}); + +test("0 denominator improper fraction", () => { + assert.equal(isProperFraction(7, 0), false); +}); + +test("Both 0 improper fraction", () => { + assert.equal(isProperFraction(0, 0), false); +}); + +test("Both equal negatives improper fraction", () => { + assert.equal(isProperFraction(-4, -4), false); +}); + +test("Negative denominator improper fraction", () => { + assert.equal(isProperFraction(2, -9), false); +}); From d5091de872befc265325603aa656aabb5c714121 Mon Sep 17 00:00:00 2001 From: russom Date: Tue, 6 Oct 2026 13:33:11 +0100 Subject: [PATCH 43/67] Update tests description. --- .../2-is-proper-fraction.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js index 2eb2ce300..12fb66067 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js @@ -42,11 +42,11 @@ test("Decimal improper fraction", () => { assert.equal(isProperFraction(1.2, 1.1), false); }); -test("Numerator larger improper fraction", () => { +test("Large numerator improper fraction", () => { assert.equal(isProperFraction(5, 3), false); }); -test("Both equal improper fraction", () => { +test("Both number equal improper fraction", () => { assert.equal(isProperFraction(4, 4), false); }); @@ -54,7 +54,7 @@ test("0 denominator improper fraction", () => { assert.equal(isProperFraction(7, 0), false); }); -test("Both 0 improper fraction", () => { +test("Both numbers 0 improper fraction", () => { assert.equal(isProperFraction(0, 0), false); }); From fa07e40aee065b377c43d69ad266985d4aad9a81 Mon Sep 17 00:00:00 2001 From: russom Date: Wed, 7 Oct 2026 21:04:42 +0100 Subject: [PATCH 44/67] Implement if condition to check card value --- implement-and-rewrite-tests/implement/3-get-card-value.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/implement-and-rewrite-tests/implement/3-get-card-value.js b/implement-and-rewrite-tests/implement/3-get-card-value.js index 9614ab1ee..cd8fa4826 100644 --- a/implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/implement-and-rewrite-tests/implement/3-get-card-value.js @@ -25,4 +25,11 @@ export function getCardValue(card) { // TODO: Implement this function + if (card === "A") { + return 11; + } else if (card === "J" || card === "Q" || card === "K") { + return 10; + } else { + return Number(card); + } } From 71c6ea1e3525272d3ef97fd47a1c7f1d080812be Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Tue, 13 Oct 2026 22:06:00 +0100 Subject: [PATCH 45/67] Write to test 0 occurrence of a character. --- 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..0575330cc 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 occurrences of a character", () => { + const str = "aaaaa"; + const char = "b"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); From c12bed8f6d21dfb2ea577387db539ea773ddf69b Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Tue, 13 Oct 2026 22:40:21 +0100 Subject: [PATCH 46/67] Implement function to check character occurrence in a string. --- practice-tdd/count.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/practice-tdd/count.js b/practice-tdd/count.js index 5518c5712..ae1557777 100644 --- a/practice-tdd/count.js +++ b/practice-tdd/count.js @@ -1,3 +1,9 @@ export function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0; + for (let i = 0; i < stringOfCharacters.length; i++) { + if (stringOfCharacters[i] === findCharacter) { + count++; + } + } + return count; } From 1b777bfaab9d8cb7eecd56deca5950b9804fdb21 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Tue, 13 Oct 2026 22:52:21 +0100 Subject: [PATCH 47/67] Refactor code. --- practice-tdd/count.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/practice-tdd/count.js b/practice-tdd/count.js index ae1557777..da4a8e004 100644 --- a/practice-tdd/count.js +++ b/practice-tdd/count.js @@ -1,7 +1,7 @@ export function countChar(stringOfCharacters, findCharacter) { let count = 0; - for (let i = 0; i < stringOfCharacters.length; i++) { - if (stringOfCharacters[i] === findCharacter) { + for (const char of stringOfCharacters) { + if (char === findCharacter) { count++; } } From 5d29d0434e36a9b094adcb325ae1fd643d3f1461 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Tue, 13 Oct 2026 22:52:43 +0100 Subject: [PATCH 48/67] Update test description. --- 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 0575330cc..33bee8d73 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -23,7 +23,7 @@ test("should count multiple occurrences of a character", () => { // 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 occurrences of a character", () => { +test("should return 0 for a character with no occurrences", () => { const str = "aaaaa"; const char = "b"; const count = countChar(str, char); From 63905f0344b800639c6517b97df049f8b0777791 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Wed, 14 Oct 2026 20:49:46 +0100 Subject: [PATCH 49/67] Write test case for numbers ending with 2 --- practice-tdd/get-ordinal-number.test.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index e23174a18..888de2582 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -18,3 +18,12 @@ 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) +// When the number ends with 2, except those ending with 12, +// Then the function should return a string by appending "nd" to the number. +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"); +}); From be0c56eca730e5a388ec828d27f2ab1ac9b6fec1 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Wed, 14 Oct 2026 20:53:39 +0100 Subject: [PATCH 50/67] Write test cases for testing numbers ending with 2. --- practice-tdd/get-ordinal-number.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 888de2582..b1503eb30 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -26,4 +26,4 @@ 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"); -}); +}); \ No newline at end of file From f05ab1dcd4492ec7f555af9c5fb8059f49851294 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Wed, 14 Oct 2026 20:56:16 +0100 Subject: [PATCH 51/67] Write test cases for testing numbers ending with 3. --- practice-tdd/get-ordinal-number.test.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index b1503eb30..7a0843b3c 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -26,4 +26,13 @@ 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: Numbers ending with 3 (but not 13) +// When the number ends with 3, except those ending with 13, +// Then the function should return a string by appending "rd" to the number. +test("should append 'nd' for numbers ending with 3, except those ending with 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(133)).toEqual("133rd"); }); \ No newline at end of file From d6e7d0675f5943616c12059f02689ef64319014e Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Wed, 14 Oct 2026 21:20:53 +0100 Subject: [PATCH 52/67] Write test cases for numbers ending with rd and th. --- practice-tdd/get-ordinal-number.test.js | 37 ++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index 7a0843b3c..f2b1dcc14 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -35,4 +35,39 @@ test("should append 'nd' for numbers ending with 3, except those ending with 13" expect(getOrdinalNumber(3)).toEqual("3rd"); expect(getOrdinalNumber(23)).toEqual("23rd"); expect(getOrdinalNumber(133)).toEqual("133rd"); -}); \ No newline at end of file +}); + +// Case 4: Numbers ending with 3 (but not 13) +// When the number ends with 3, except those ending with 13, +// Then the function should return a string by appending "rd" to the number. +test("should append 'nd' for numbers ending with 3, except those ending with 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(133)).toEqual("133rd"); +}); + +// Case 5: All numbers (but not 1, 2, and 3) +// When the number ends with any number, except those ending with 1, 2, and 3, +// Then the function should return a string by appending "th" to the number. +test("should append 'th' for numbers ending with any number, except those ending with 1, 2, and 3", () => { + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); +}); + +// Case 6: All numbers (but not 1, 2, and 3) +// When the number ends with any number, except those ending with 1, 2, and 3, +// Then the function should return a string by appending "th" to the number. +test("should append 'th' for numbers ending with any number, except those ending with 1, 2, and 3", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(9)).toEqual("9th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(14)).toEqual("14th"); + expect(getOrdinalNumber(20)).toEqual("20th"); + expect(getOrdinalNumber(24)).toEqual("24th"); + expect(getOrdinalNumber(100)).toEqual("100th"); + expect(getOrdinalNumber(134)).toEqual("134th"); +}); + + From 2431fdfc4ae9753104fa03c5fe356b041be77793 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Wed, 14 Oct 2026 21:28:32 +0100 Subject: [PATCH 53/67] Update test description. --- practice-tdd/get-ordinal-number.test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index f2b1dcc14..c9daf1642 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -46,11 +46,10 @@ test("should append 'nd' for numbers ending with 3, except those ending with 13" expect(getOrdinalNumber(133)).toEqual("133rd"); }); -// Case 5: All numbers (but not 1, 2, and 3) -// When the number ends with any number, except those ending with 1, 2, and 3, +// Case 5: Exception for teen numbers ending with 1, 2, or 3. +// When the teen number ends with 1, 2, or 3, // Then the function should return a string by appending "th" to the number. -test("should append 'th' for numbers ending with any number, except those ending with 1, 2, and 3", () => { - expect(getOrdinalNumber(10)).toEqual("10th"); +test("should append 'th' for teen numbers ending with 1, 2, or 3,", () => { expect(getOrdinalNumber(11)).toEqual("11th"); expect(getOrdinalNumber(12)).toEqual("12th"); expect(getOrdinalNumber(13)).toEqual("13th"); From 74213729e0bc6c8bf8a53b1b2de88626f47592f7 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Wed, 14 Oct 2026 22:21:50 +0100 Subject: [PATCH 54/67] Implement a function for checking ordinal numbers and their suffixes. --- practice-tdd/get-ordinal-number.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 5c6291f5e..1db6a3c5a 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,3 +1,15 @@ export function getOrdinalNumber(num) { - return "1st"; + const lastDigit = num % 10; + const lastTwoDigit = num % 100; + + if (lastDigit === 1 && lastTwoDigit !== 11) { + return `${num}st`; + } + if (lastDigit === 2 && lastTwoDigit !== 12) { + return `${num}nd`; + } + if (lastDigit === 3 && lastTwoDigit !== 13) { + return `${num}rd`; + } + return `${num}th`; } From 51a72347215c6469e735a04bb04edfe36b651ed1 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Wed, 14 Oct 2026 22:22:38 +0100 Subject: [PATCH 55/67] Refactor test cases. --- practice-tdd/get-ordinal-number.test.js | 41 ++++++++++--------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index c9daf1642..fb046ec44 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -31,42 +31,35 @@ test("should append 'nd' for numbers ending with 2, except those ending with 12" // Case 3: Numbers ending with 3 (but not 13) // When the number ends with 3, except those ending with 13, // Then the function should return a string by appending "rd" to the number. -test("should append 'nd' for numbers ending with 3, except those ending with 13", () => { +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(133)).toEqual("133rd"); }); -// Case 4: Numbers ending with 3 (but not 13) -// When the number ends with 3, except those ending with 13, -// Then the function should return a string by appending "rd" to the number. -test("should append 'nd' for numbers ending with 3, except those ending with 13", () => { - expect(getOrdinalNumber(3)).toEqual("3rd"); - expect(getOrdinalNumber(23)).toEqual("23rd"); - expect(getOrdinalNumber(133)).toEqual("133rd"); -}); - -// Case 5: Exception for teen numbers ending with 1, 2, or 3. -// When the teen number ends with 1, 2, or 3, -// Then the function should return a string by appending "th" to the number. -test("should append 'th' for teen numbers ending with 1, 2, or 3,", () => { +// Case 4: Exception for 11, 12 and 13. +// When a number ends with 11, 12 and 13, +// Then the function should return a string by appending "th" not st, nd or rd. +test("should append 'th' for numbers ending with 11, 12 and 13", () => { expect(getOrdinalNumber(11)).toEqual("11th"); expect(getOrdinalNumber(12)).toEqual("12th"); expect(getOrdinalNumber(13)).toEqual("13th"); }); -// Case 6: All numbers (but not 1, 2, and 3) -// When the number ends with any number, except those ending with 1, 2, and 3, +// Case 5: Numbers ending with 4 to 9. +// When the number ends with 4 to 9, // Then the function should return a string by appending "th" to the number. -test("should append 'th' for numbers ending with any number, except those ending with 1, 2, and 3", () => { +test("should append 'th' for numbers ending with 4 to 9", () => { expect(getOrdinalNumber(4)).toEqual("4th"); - expect(getOrdinalNumber(9)).toEqual("9th"); - expect(getOrdinalNumber(10)).toEqual("10th"); expect(getOrdinalNumber(14)).toEqual("14th"); - expect(getOrdinalNumber(20)).toEqual("20th"); - expect(getOrdinalNumber(24)).toEqual("24th"); - expect(getOrdinalNumber(100)).toEqual("100th"); - expect(getOrdinalNumber(134)).toEqual("134th"); + expect(getOrdinalNumber(144)).toEqual("144th"); }); - +// Case 6: Numbers ending with 0. +// When the number ends with 0, +// Then the function should return a string by appending "th" to the number. +test("should append 'th' for numbers ending with 0", () => { + expect(getOrdinalNumber(0)).toEqual("0th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(100)).toEqual("100th"); +}); From 7465a374d705ef02ce4de9ee0550f5bbdbdcb7fe Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Thu, 15 Oct 2026 23:06:42 +0100 Subject: [PATCH 56/67] Write test case for repeating 1 times --- 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..e97f14703 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -20,6 +20,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, From b5ed6aeb632346d849b6d2e30410b1026a14382b Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Thu, 15 Oct 2026 23:08:03 +0100 Subject: [PATCH 57/67] Write test case for repeating 0 times. --- 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 e97f14703..b8476fc28 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -31,6 +31,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(""); +}); // Case: Handle negative count: // Given a target string `str` and a negative integer `count`, From d363d13403965580a09449d3ff51038e58a95b44 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Thu, 15 Oct 2026 23:10:46 +0100 Subject: [PATCH 58/67] Write test case for repeating -1 times. --- 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 b8476fc28..fd462ea3a 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -42,3 +42,9 @@ 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", () => { + const str = "hello"; + const count = -1; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual(""); +}); \ No newline at end of file From bd5de48a2cdd12f4cf3d45ba533118b61d968c19 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Fri, 16 Oct 2026 21:20:38 +0100 Subject: [PATCH 59/67] Implement function that repeats string a number of times. --- practice-tdd/repeat-str.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index af273f3b0..f930dc677 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,5 +1,13 @@ -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. - return "hellohellohello"; + if (count < 0) { + throw new Error("Count must not be negative"); + } + + let repeat = ""; + for (let i = 0; i < count; i++) { + repeat += str; + } + return repeat; } From 616bbbf6567c7e5d7ff8cfee169445a765a04fbe Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Fri, 16 Oct 2026 21:21:50 +0100 Subject: [PATCH 60/67] Write test case to test negative input. --- practice-tdd/repeat-str.test.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index fd462ea3a..3587cf314 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -31,7 +31,7 @@ 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", () => { +test("should return an empty string", () => { const str = "hello"; const count = 0; const repeatedStr = repeatStr(str, count); @@ -42,9 +42,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", () => { +test("should throw an error", () => { const str = "hello"; const count = -1; - const repeatedStr = repeatStr(str, count); - expect(repeatedStr).toEqual(""); -}); \ No newline at end of file + expect(() => repeatStr(str, count)).toThrow("Count must not be negative"); +}); From 2de2d40884c3af2842ba857fdbe0916fbdca86ca Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Fri, 16 Oct 2026 21:38:58 +0100 Subject: [PATCH 61/67] Remove exercise folders from repo --- dead-code/exercise-1.js | 11 ++++ dead-code/exercise-2.js | 31 ++++++----- .../1-get-angle-type.test.js | 52 ------------------ .../2-is-proper-fraction.test.js | 55 ------------------- .../implement/1-get-angle-type.js | 13 ----- .../implement/2-is-proper-fraction.js | 6 -- .../implement/3-get-card-value.js | 7 --- practice-tdd/count.js | 8 +-- practice-tdd/count.test.js | 7 --- practice-tdd/get-ordinal-number.js | 14 +---- practice-tdd/get-ordinal-number.test.js | 45 --------------- practice-tdd/repeat-str.js | 12 +--- practice-tdd/repeat-str.test.js | 17 ------ 13 files changed, 32 insertions(+), 246 deletions(-) diff --git a/dead-code/exercise-1.js b/dead-code/exercise-1.js index 5593f9e23..4d09f15fa 100644 --- a/dead-code/exercise-1.js +++ b/dead-code/exercise-1.js @@ -1,6 +1,17 @@ // Find the instances of unreachable and redundant code - remove them! // The sayHello function should continue to work for any reasonable input it's given. +let testName = "Jerry"; +const greeting = "hello"; + function sayHello(greeting, name) { + const greetingStr = greeting + ", " + name + "!"; return `${greeting}, ${name}!`; + console.log(greetingStr); } + +testName = "Aman"; + +const greetingMessage = sayHello(greeting, testName); + +console.log(greetingMessage); // 'hello, Aman!' diff --git a/dead-code/exercise-2.js b/dead-code/exercise-2.js index 16ca0657e..56d7887c4 100644 --- a/dead-code/exercise-2.js +++ b/dead-code/exercise-2.js @@ -2,24 +2,27 @@ // The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; +const capitalisedPets = pets.map((pet) => pet.toUpperCase()); +const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); + +function logPets(petsArr) { + petsArr.forEach((pet) => console.log(pet)); +} function countAndCapitalisePets(petsArr) { const petCount = {}; - petsArr - .filter((pet) => pet[0] === "h") - .forEach((pet) => { - const capitalisedPet = pet.toUpperCase(); - - if (petCount[capitalisedPet]) { - petCount[capitalisedPet] += 1; - } else { - petCount[capitalisedPet] = 1; - } - }); - + petsArr.forEach((pet) => { + const capitalisedPet = pet.toUpperCase(); + if (petCount[capitalisedPet]) { + petCount[capitalisedPet] += 1; + } else { + petCount[capitalisedPet] = 1; + } + }); return petCount; } -const animals = ["lion", "hyena", "elephant", "hippo", "tiger", "hippo"]; -console.log(countAndCapitalisePets(animals)); +const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH); + +console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js index 4a3d88089..cf50f6cad 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js @@ -6,59 +6,7 @@ import { getAngleType } from "../implement/1-get-angle-type.js"; // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles -test("Classifies Acute angles", () => { - const Acute = getAngleType(1); - assert.equal(Acute, "Acute angle"); - - const Acute1 = getAngleType(45); - assert.equal(Acute1, "Acute angle"); - - const Acute2 = getAngleType(89); - assert.equal(Acute2, "Acute angle"); -}); - test("Classifies right angles", () => { const right = getAngleType(90); assert.equal(right, "Right angle"); }); - -test("Classifies Obtuse angles", () => { - const Obtuse = getAngleType(91); - assert.equal(Obtuse, "Obtuse angle"); - - const Obtuse1 = getAngleType(120); - assert.equal(Obtuse1, "Obtuse angle"); - - const Obtuse2 = getAngleType(179); - assert.equal(Obtuse2, "Obtuse angle"); -}); - -test("Classifies Straight angles", () => { - const Straight = getAngleType(180); - assert.equal(Straight, "Straight angle"); -}); - -test("Classifies Reflex angles", () => { - const Reflex = getAngleType(181); - assert.equal(Reflex, "Reflex angle"); - - const Reflex1 = getAngleType(299); - assert.equal(Reflex1, "Reflex angle"); - - const Reflex2 = getAngleType(360); - assert.equal(Reflex2, "Reflex angle"); -}); - -test("Classifies Invalid angles", () => { - const Invalid = getAngleType(0); - assert.equal(Invalid, "Invalid angle"); - - const Invalid1 = getAngleType(361); - assert.equal(Invalid1, "Invalid angle"); - - const Invalid2 = getAngleType(399); - assert.equal(Invalid2, "Invalid angle"); - - const Invalid3 = getAngleType(-7); - assert.equal(Invalid3, "Invalid angle"); -}); diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js index 12fb66067..a29084605 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js @@ -10,58 +10,3 @@ test("Basic proper fraction", () => { // Example: 1/2 is a proper fraction assert.equal(isProperFraction(1, 2), true); }); - -// Proper fraction -test("Decimal proper fraction", () => { - assert.equal(isProperFraction(0.5, 1.5), true); -}); - -test("0 numerator proper fraction", () => { - assert.equal(isProperFraction(0, 5), true); -}); - -test("Negative numerator proper fraction", () => { - assert.equal(isProperFraction(-9, 1), true); -}); - -test("Both negatives proper fraction", () => { - assert.equal(isProperFraction(-7, -3), true); -}); - -test("Large number proper fraction", () => { - assert.equal(isProperFraction(999, 1000), true); -}); - -test("Very small denominator proper fraction", () => { - assert.equal(isProperFraction(1, 1000000), true); -}); - -// Improper fractions - -test("Decimal improper fraction", () => { - assert.equal(isProperFraction(1.2, 1.1), false); -}); - -test("Large numerator improper fraction", () => { - assert.equal(isProperFraction(5, 3), false); -}); - -test("Both number equal improper fraction", () => { - assert.equal(isProperFraction(4, 4), false); -}); - -test("0 denominator improper fraction", () => { - assert.equal(isProperFraction(7, 0), false); -}); - -test("Both numbers 0 improper fraction", () => { - assert.equal(isProperFraction(0, 0), false); -}); - -test("Both equal negatives improper fraction", () => { - assert.equal(isProperFraction(-4, -4), false); -}); - -test("Negative denominator improper fraction", () => { - assert.equal(isProperFraction(2, -9), false); -}); diff --git a/implement-and-rewrite-tests/implement/1-get-angle-type.js b/implement-and-rewrite-tests/implement/1-get-angle-type.js index e10c0d61d..8a6fba050 100644 --- a/implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -18,17 +18,4 @@ export function getAngleType(angle) { // TODO: Implement this function - if (angle > 0 && angle < 90) { - return "Acute angle"; - } else if (angle === 90) { - return "Right angle"; - } else if (angle > 90 && angle < 180) { - return "Obtuse angle"; - } else if (angle === 180) { - return "Straight angle"; - } else if (angle > 180 && angle <= 360) { - return "Reflex angle"; - } else { - return "Invalid angle"; - } } diff --git a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js index a8fcfbbc7..f983800f0 100644 --- a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -15,10 +15,4 @@ export function isProperFraction(numerator, denominator) { // TODO: Implement this function - if (numerator < denominator) { - return true; - } else { - return false; - } } - diff --git a/implement-and-rewrite-tests/implement/3-get-card-value.js b/implement-and-rewrite-tests/implement/3-get-card-value.js index cd8fa4826..9614ab1ee 100644 --- a/implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/implement-and-rewrite-tests/implement/3-get-card-value.js @@ -25,11 +25,4 @@ export function getCardValue(card) { // TODO: Implement this function - if (card === "A") { - return 11; - } else if (card === "J" || card === "Q" || card === "K") { - return 10; - } else { - return Number(card); - } } diff --git a/practice-tdd/count.js b/practice-tdd/count.js index da4a8e004..5518c5712 100644 --- a/practice-tdd/count.js +++ b/practice-tdd/count.js @@ -1,9 +1,3 @@ export function countChar(stringOfCharacters, findCharacter) { - let count = 0; - for (const char of stringOfCharacters) { - if (char === findCharacter) { - count++; - } - } - return count; + return 5 } diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index 33bee8d73..cb3aaae59 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -22,10 +22,3 @@ 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 for a character with no occurrences", () => { - const str = "aaaaa"; - const char = "b"; - const count = countChar(str, char); - expect(count).toEqual(0); -}); diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 1db6a3c5a..5c6291f5e 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,15 +1,3 @@ export function getOrdinalNumber(num) { - const lastDigit = num % 10; - const lastTwoDigit = num % 100; - - if (lastDigit === 1 && lastTwoDigit !== 11) { - return `${num}st`; - } - if (lastDigit === 2 && lastTwoDigit !== 12) { - return `${num}nd`; - } - if (lastDigit === 3 && lastTwoDigit !== 13) { - return `${num}rd`; - } - return `${num}th`; + return "1st"; } diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index fb046ec44..e23174a18 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -18,48 +18,3 @@ 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) -// When the number ends with 2, except those ending with 12, -// Then the function should return a string by appending "nd" to the number. -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: Numbers ending with 3 (but not 13) -// When the number ends with 3, except those ending with 13, -// Then the function should return a string by appending "rd" to the number. -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(133)).toEqual("133rd"); -}); - -// Case 4: Exception for 11, 12 and 13. -// When a number ends with 11, 12 and 13, -// Then the function should return a string by appending "th" not st, nd or rd. -test("should append 'th' for numbers ending with 11, 12 and 13", () => { - expect(getOrdinalNumber(11)).toEqual("11th"); - expect(getOrdinalNumber(12)).toEqual("12th"); - expect(getOrdinalNumber(13)).toEqual("13th"); -}); - -// Case 5: Numbers ending with 4 to 9. -// When the number ends with 4 to 9, -// Then the function should return a string by appending "th" to the number. -test("should append 'th' for numbers ending with 4 to 9", () => { - expect(getOrdinalNumber(4)).toEqual("4th"); - expect(getOrdinalNumber(14)).toEqual("14th"); - expect(getOrdinalNumber(144)).toEqual("144th"); -}); - -// Case 6: Numbers ending with 0. -// When the number ends with 0, -// Then the function should return a string by appending "th" to the number. -test("should append 'th' for numbers ending with 0", () => { - expect(getOrdinalNumber(0)).toEqual("0th"); - expect(getOrdinalNumber(10)).toEqual("10th"); - expect(getOrdinalNumber(100)).toEqual("100th"); -}); diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index f930dc677..af273f3b0 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,13 +1,5 @@ -export function repeatStr(str, count) { +export 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. - if (count < 0) { - throw new Error("Count must not be negative"); - } - - let repeat = ""; - for (let i = 0; i < count; i++) { - repeat += str; - } - return repeat; + return "hellohellohello"; } diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 3587cf314..8a7036102 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -20,30 +20,13 @@ 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, // Then it should return an empty string. -test("should return an empty string", () => { - 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", () => { - const str = "hello"; - const count = -1; - expect(() => repeatStr(str, count)).toThrow("Count must not be negative"); -}); From 05f3e6e013eee456e5b206fd79ef92291ad486c5 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Fri, 16 Oct 2026 21:52:09 +0100 Subject: [PATCH 62/67] Restore files to state before removal --- dead-code/exercise-1.js | 11 ---- dead-code/exercise-2.js | 31 +++++------ .../1-get-angle-type.test.js | 52 ++++++++++++++++++ .../2-is-proper-fraction.test.js | 55 +++++++++++++++++++ .../implement/1-get-angle-type.js | 13 +++++ .../implement/2-is-proper-fraction.js | 6 ++ .../implement/3-get-card-value.js | 7 +++ practice-tdd/count.js | 8 ++- practice-tdd/count.test.js | 7 +++ practice-tdd/get-ordinal-number.js | 14 ++++- practice-tdd/get-ordinal-number.test.js | 45 +++++++++++++++ practice-tdd/repeat-str.js | 12 +++- practice-tdd/repeat-str.test.js | 17 ++++++ 13 files changed, 246 insertions(+), 32 deletions(-) diff --git a/dead-code/exercise-1.js b/dead-code/exercise-1.js index 4d09f15fa..5593f9e23 100644 --- a/dead-code/exercise-1.js +++ b/dead-code/exercise-1.js @@ -1,17 +1,6 @@ // Find the instances of unreachable and redundant code - remove them! // The sayHello function should continue to work for any reasonable input it's given. -let testName = "Jerry"; -const greeting = "hello"; - function sayHello(greeting, name) { - const greetingStr = greeting + ", " + name + "!"; return `${greeting}, ${name}!`; - console.log(greetingStr); } - -testName = "Aman"; - -const greetingMessage = sayHello(greeting, testName); - -console.log(greetingMessage); // 'hello, Aman!' diff --git a/dead-code/exercise-2.js b/dead-code/exercise-2.js index 56d7887c4..16ca0657e 100644 --- a/dead-code/exercise-2.js +++ b/dead-code/exercise-2.js @@ -2,27 +2,24 @@ // The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; -const capitalisedPets = pets.map((pet) => pet.toUpperCase()); -const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); - -function logPets(petsArr) { - petsArr.forEach((pet) => console.log(pet)); -} function countAndCapitalisePets(petsArr) { const petCount = {}; - petsArr.forEach((pet) => { - const capitalisedPet = pet.toUpperCase(); - if (petCount[capitalisedPet]) { - petCount[capitalisedPet] += 1; - } else { - petCount[capitalisedPet] = 1; - } - }); + petsArr + .filter((pet) => pet[0] === "h") + .forEach((pet) => { + const capitalisedPet = pet.toUpperCase(); + + if (petCount[capitalisedPet]) { + petCount[capitalisedPet] += 1; + } else { + petCount[capitalisedPet] = 1; + } + }); + return petCount; } -const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH); - -console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log +const animals = ["lion", "hyena", "elephant", "hippo", "tiger", "hippo"]; +console.log(countAndCapitalisePets(animals)); diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js index cf50f6cad..4a3d88089 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js @@ -6,7 +6,59 @@ import { getAngleType } from "../implement/1-get-angle-type.js"; // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles +test("Classifies Acute angles", () => { + const Acute = getAngleType(1); + assert.equal(Acute, "Acute angle"); + + const Acute1 = getAngleType(45); + assert.equal(Acute1, "Acute angle"); + + const Acute2 = getAngleType(89); + assert.equal(Acute2, "Acute angle"); +}); + test("Classifies right angles", () => { const right = getAngleType(90); assert.equal(right, "Right angle"); }); + +test("Classifies Obtuse angles", () => { + const Obtuse = getAngleType(91); + assert.equal(Obtuse, "Obtuse angle"); + + const Obtuse1 = getAngleType(120); + assert.equal(Obtuse1, "Obtuse angle"); + + const Obtuse2 = getAngleType(179); + assert.equal(Obtuse2, "Obtuse angle"); +}); + +test("Classifies Straight angles", () => { + const Straight = getAngleType(180); + assert.equal(Straight, "Straight angle"); +}); + +test("Classifies Reflex angles", () => { + const Reflex = getAngleType(181); + assert.equal(Reflex, "Reflex angle"); + + const Reflex1 = getAngleType(299); + assert.equal(Reflex1, "Reflex angle"); + + const Reflex2 = getAngleType(360); + assert.equal(Reflex2, "Reflex angle"); +}); + +test("Classifies Invalid angles", () => { + const Invalid = getAngleType(0); + assert.equal(Invalid, "Invalid angle"); + + const Invalid1 = getAngleType(361); + assert.equal(Invalid1, "Invalid angle"); + + const Invalid2 = getAngleType(399); + assert.equal(Invalid2, "Invalid angle"); + + const Invalid3 = getAngleType(-7); + assert.equal(Invalid3, "Invalid angle"); +}); diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js index a29084605..12fb66067 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js @@ -10,3 +10,58 @@ test("Basic proper fraction", () => { // Example: 1/2 is a proper fraction assert.equal(isProperFraction(1, 2), true); }); + +// Proper fraction +test("Decimal proper fraction", () => { + assert.equal(isProperFraction(0.5, 1.5), true); +}); + +test("0 numerator proper fraction", () => { + assert.equal(isProperFraction(0, 5), true); +}); + +test("Negative numerator proper fraction", () => { + assert.equal(isProperFraction(-9, 1), true); +}); + +test("Both negatives proper fraction", () => { + assert.equal(isProperFraction(-7, -3), true); +}); + +test("Large number proper fraction", () => { + assert.equal(isProperFraction(999, 1000), true); +}); + +test("Very small denominator proper fraction", () => { + assert.equal(isProperFraction(1, 1000000), true); +}); + +// Improper fractions + +test("Decimal improper fraction", () => { + assert.equal(isProperFraction(1.2, 1.1), false); +}); + +test("Large numerator improper fraction", () => { + assert.equal(isProperFraction(5, 3), false); +}); + +test("Both number equal improper fraction", () => { + assert.equal(isProperFraction(4, 4), false); +}); + +test("0 denominator improper fraction", () => { + assert.equal(isProperFraction(7, 0), false); +}); + +test("Both numbers 0 improper fraction", () => { + assert.equal(isProperFraction(0, 0), false); +}); + +test("Both equal negatives improper fraction", () => { + assert.equal(isProperFraction(-4, -4), false); +}); + +test("Negative denominator improper fraction", () => { + assert.equal(isProperFraction(2, -9), false); +}); diff --git a/implement-and-rewrite-tests/implement/1-get-angle-type.js b/implement-and-rewrite-tests/implement/1-get-angle-type.js index 8a6fba050..e10c0d61d 100644 --- a/implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -18,4 +18,17 @@ export function getAngleType(angle) { // TODO: Implement this function + if (angle > 0 && angle < 90) { + return "Acute angle"; + } else if (angle === 90) { + return "Right angle"; + } else if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } else if (angle === 180) { + return "Straight angle"; + } else if (angle > 180 && angle <= 360) { + return "Reflex angle"; + } else { + return "Invalid angle"; + } } diff --git a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js index f983800f0..a8fcfbbc7 100644 --- a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -15,4 +15,10 @@ export function isProperFraction(numerator, denominator) { // TODO: Implement this function + if (numerator < denominator) { + return true; + } else { + return false; + } } + diff --git a/implement-and-rewrite-tests/implement/3-get-card-value.js b/implement-and-rewrite-tests/implement/3-get-card-value.js index 9614ab1ee..cd8fa4826 100644 --- a/implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/implement-and-rewrite-tests/implement/3-get-card-value.js @@ -25,4 +25,11 @@ export function getCardValue(card) { // TODO: Implement this function + if (card === "A") { + return 11; + } else if (card === "J" || card === "Q" || card === "K") { + return 10; + } else { + return Number(card); + } } diff --git a/practice-tdd/count.js b/practice-tdd/count.js index 5518c5712..da4a8e004 100644 --- a/practice-tdd/count.js +++ b/practice-tdd/count.js @@ -1,3 +1,9 @@ export function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0; + for (const char of stringOfCharacters) { + if (char === findCharacter) { + count++; + } + } + return count; } diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index cb3aaae59..33bee8d73 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 return 0 for a character with no occurrences", () => { + const str = "aaaaa"; + const char = "b"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js index 5c6291f5e..1db6a3c5a 100644 --- a/practice-tdd/get-ordinal-number.js +++ b/practice-tdd/get-ordinal-number.js @@ -1,3 +1,15 @@ export function getOrdinalNumber(num) { - return "1st"; + const lastDigit = num % 10; + const lastTwoDigit = num % 100; + + if (lastDigit === 1 && lastTwoDigit !== 11) { + return `${num}st`; + } + if (lastDigit === 2 && lastTwoDigit !== 12) { + return `${num}nd`; + } + if (lastDigit === 3 && lastTwoDigit !== 13) { + return `${num}rd`; + } + return `${num}th`; } diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index e23174a18..fb046ec44 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -18,3 +18,48 @@ 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) +// When the number ends with 2, except those ending with 12, +// Then the function should return a string by appending "nd" to the number. +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: Numbers ending with 3 (but not 13) +// When the number ends with 3, except those ending with 13, +// Then the function should return a string by appending "rd" to the number. +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(133)).toEqual("133rd"); +}); + +// Case 4: Exception for 11, 12 and 13. +// When a number ends with 11, 12 and 13, +// Then the function should return a string by appending "th" not st, nd or rd. +test("should append 'th' for numbers ending with 11, 12 and 13", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); +}); + +// Case 5: Numbers ending with 4 to 9. +// When the number ends with 4 to 9, +// Then the function should return a string by appending "th" to the number. +test("should append 'th' for numbers ending with 4 to 9", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(14)).toEqual("14th"); + expect(getOrdinalNumber(144)).toEqual("144th"); +}); + +// Case 6: Numbers ending with 0. +// When the number ends with 0, +// Then the function should return a string by appending "th" to the number. +test("should append 'th' for numbers ending with 0", () => { + expect(getOrdinalNumber(0)).toEqual("0th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(100)).toEqual("100th"); +}); diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js index af273f3b0..f930dc677 100644 --- a/practice-tdd/repeat-str.js +++ b/practice-tdd/repeat-str.js @@ -1,5 +1,13 @@ -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. - return "hellohellohello"; + if (count < 0) { + throw new Error("Count must not be negative"); + } + + let repeat = ""; + for (let i = 0; i < count; i++) { + repeat += str; + } + return repeat; } diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 8a7036102..3587cf314 100644 --- a/practice-tdd/repeat-str.test.js +++ b/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 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 return an empty string", () => { + 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", () => { + const str = "hello"; + const count = -1; + expect(() => repeatStr(str, count)).toThrow("Count must not be negative"); +}); From ba2ebd031320282cc3531cdca7d5efd53d180bc7 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Fri, 16 Oct 2026 21:54:41 +0100 Subject: [PATCH 63/67] Restore practice-tdd work and remove files from other branches --- dead-code/exercise-1.js | 11 ++++ dead-code/exercise-2.js | 31 ++++++----- .../1-get-angle-type.test.js | 52 ------------------ .../2-is-proper-fraction.test.js | 55 ------------------- .../implement/1-get-angle-type.js | 13 ----- .../implement/2-is-proper-fraction.js | 6 -- .../implement/3-get-card-value.js | 7 --- 7 files changed, 28 insertions(+), 147 deletions(-) diff --git a/dead-code/exercise-1.js b/dead-code/exercise-1.js index 5593f9e23..4d09f15fa 100644 --- a/dead-code/exercise-1.js +++ b/dead-code/exercise-1.js @@ -1,6 +1,17 @@ // Find the instances of unreachable and redundant code - remove them! // The sayHello function should continue to work for any reasonable input it's given. +let testName = "Jerry"; +const greeting = "hello"; + function sayHello(greeting, name) { + const greetingStr = greeting + ", " + name + "!"; return `${greeting}, ${name}!`; + console.log(greetingStr); } + +testName = "Aman"; + +const greetingMessage = sayHello(greeting, testName); + +console.log(greetingMessage); // 'hello, Aman!' diff --git a/dead-code/exercise-2.js b/dead-code/exercise-2.js index 16ca0657e..56d7887c4 100644 --- a/dead-code/exercise-2.js +++ b/dead-code/exercise-2.js @@ -2,24 +2,27 @@ // The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; +const capitalisedPets = pets.map((pet) => pet.toUpperCase()); +const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); + +function logPets(petsArr) { + petsArr.forEach((pet) => console.log(pet)); +} function countAndCapitalisePets(petsArr) { const petCount = {}; - petsArr - .filter((pet) => pet[0] === "h") - .forEach((pet) => { - const capitalisedPet = pet.toUpperCase(); - - if (petCount[capitalisedPet]) { - petCount[capitalisedPet] += 1; - } else { - petCount[capitalisedPet] = 1; - } - }); - + petsArr.forEach((pet) => { + const capitalisedPet = pet.toUpperCase(); + if (petCount[capitalisedPet]) { + petCount[capitalisedPet] += 1; + } else { + petCount[capitalisedPet] = 1; + } + }); return petCount; } -const animals = ["lion", "hyena", "elephant", "hippo", "tiger", "hippo"]; -console.log(countAndCapitalisePets(animals)); +const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH); + +console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js index 4a3d88089..cf50f6cad 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js @@ -6,59 +6,7 @@ import { getAngleType } from "../implement/1-get-angle-type.js"; // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles -test("Classifies Acute angles", () => { - const Acute = getAngleType(1); - assert.equal(Acute, "Acute angle"); - - const Acute1 = getAngleType(45); - assert.equal(Acute1, "Acute angle"); - - const Acute2 = getAngleType(89); - assert.equal(Acute2, "Acute angle"); -}); - test("Classifies right angles", () => { const right = getAngleType(90); assert.equal(right, "Right angle"); }); - -test("Classifies Obtuse angles", () => { - const Obtuse = getAngleType(91); - assert.equal(Obtuse, "Obtuse angle"); - - const Obtuse1 = getAngleType(120); - assert.equal(Obtuse1, "Obtuse angle"); - - const Obtuse2 = getAngleType(179); - assert.equal(Obtuse2, "Obtuse angle"); -}); - -test("Classifies Straight angles", () => { - const Straight = getAngleType(180); - assert.equal(Straight, "Straight angle"); -}); - -test("Classifies Reflex angles", () => { - const Reflex = getAngleType(181); - assert.equal(Reflex, "Reflex angle"); - - const Reflex1 = getAngleType(299); - assert.equal(Reflex1, "Reflex angle"); - - const Reflex2 = getAngleType(360); - assert.equal(Reflex2, "Reflex angle"); -}); - -test("Classifies Invalid angles", () => { - const Invalid = getAngleType(0); - assert.equal(Invalid, "Invalid angle"); - - const Invalid1 = getAngleType(361); - assert.equal(Invalid1, "Invalid angle"); - - const Invalid2 = getAngleType(399); - assert.equal(Invalid2, "Invalid angle"); - - const Invalid3 = getAngleType(-7); - assert.equal(Invalid3, "Invalid angle"); -}); diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js index 12fb66067..a29084605 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js @@ -10,58 +10,3 @@ test("Basic proper fraction", () => { // Example: 1/2 is a proper fraction assert.equal(isProperFraction(1, 2), true); }); - -// Proper fraction -test("Decimal proper fraction", () => { - assert.equal(isProperFraction(0.5, 1.5), true); -}); - -test("0 numerator proper fraction", () => { - assert.equal(isProperFraction(0, 5), true); -}); - -test("Negative numerator proper fraction", () => { - assert.equal(isProperFraction(-9, 1), true); -}); - -test("Both negatives proper fraction", () => { - assert.equal(isProperFraction(-7, -3), true); -}); - -test("Large number proper fraction", () => { - assert.equal(isProperFraction(999, 1000), true); -}); - -test("Very small denominator proper fraction", () => { - assert.equal(isProperFraction(1, 1000000), true); -}); - -// Improper fractions - -test("Decimal improper fraction", () => { - assert.equal(isProperFraction(1.2, 1.1), false); -}); - -test("Large numerator improper fraction", () => { - assert.equal(isProperFraction(5, 3), false); -}); - -test("Both number equal improper fraction", () => { - assert.equal(isProperFraction(4, 4), false); -}); - -test("0 denominator improper fraction", () => { - assert.equal(isProperFraction(7, 0), false); -}); - -test("Both numbers 0 improper fraction", () => { - assert.equal(isProperFraction(0, 0), false); -}); - -test("Both equal negatives improper fraction", () => { - assert.equal(isProperFraction(-4, -4), false); -}); - -test("Negative denominator improper fraction", () => { - assert.equal(isProperFraction(2, -9), false); -}); diff --git a/implement-and-rewrite-tests/implement/1-get-angle-type.js b/implement-and-rewrite-tests/implement/1-get-angle-type.js index e10c0d61d..8a6fba050 100644 --- a/implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -18,17 +18,4 @@ export function getAngleType(angle) { // TODO: Implement this function - if (angle > 0 && angle < 90) { - return "Acute angle"; - } else if (angle === 90) { - return "Right angle"; - } else if (angle > 90 && angle < 180) { - return "Obtuse angle"; - } else if (angle === 180) { - return "Straight angle"; - } else if (angle > 180 && angle <= 360) { - return "Reflex angle"; - } else { - return "Invalid angle"; - } } diff --git a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js index a8fcfbbc7..f983800f0 100644 --- a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -15,10 +15,4 @@ export function isProperFraction(numerator, denominator) { // TODO: Implement this function - if (numerator < denominator) { - return true; - } else { - return false; - } } - diff --git a/implement-and-rewrite-tests/implement/3-get-card-value.js b/implement-and-rewrite-tests/implement/3-get-card-value.js index cd8fa4826..9614ab1ee 100644 --- a/implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/implement-and-rewrite-tests/implement/3-get-card-value.js @@ -25,11 +25,4 @@ export function getCardValue(card) { // TODO: Implement this function - if (card === "A") { - return 11; - } else if (card === "J" || card === "Q" || card === "K") { - return 10; - } else { - return Number(card); - } } From 264105223e825acedfbcc8a7c3e34f8546e0ad56 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Fri, 23 Oct 2026 12:24:35 +0100 Subject: [PATCH 64/67] Add more test case for multiple occurrence. --- 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 33bee8d73..cec937168 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -17,6 +17,13 @@ test("should count multiple occurrences of a character", () => { expect(count).toEqual(5); }); +test("should count multiple occurrences of a character", () => { + const str = "apple"; + const char = "p"; + const count = countChar(str, char); + expect(count).toEqual(2); +}); + // Scenario: No Occurrences // Given the input string `str`, // And a character `char` that does not exist within `str`. From ddd89851027b8730d9ec1ed40db186525351ebc8 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Fri, 23 Oct 2026 12:28:03 +0100 Subject: [PATCH 65/67] Update test case input with empty string. --- 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 cec937168..58cb3798b 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -32,7 +32,7 @@ test("should count multiple occurrences of a character", () => { test("should return 0 for a character with no occurrences", () => { const str = "aaaaa"; - const char = "b"; + const char = ""; const count = countChar(str, char); expect(count).toEqual(0); }); From e21c39ae2bb6464b0cb2b47faa7402a180022c01 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Fri, 23 Oct 2026 12:31:37 +0100 Subject: [PATCH 66/67] Add more test cases for large numbers. --- practice-tdd/get-ordinal-number.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js index fb046ec44..0dd7f0cc2 100644 --- a/practice-tdd/get-ordinal-number.test.js +++ b/practice-tdd/get-ordinal-number.test.js @@ -44,6 +44,9 @@ test("should append 'th' for numbers ending with 11, 12 and 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(1113)).toEqual("1113th"); }); // Case 5: Numbers ending with 4 to 9. From 96ea429e24e5753a6718e71ecc531d1e521a2d50 Mon Sep 17 00:00:00 2001 From: Russom Gebremeskel Date: Fri, 23 Oct 2026 12:42:05 +0100 Subject: [PATCH 67/67] Add test case for empty string input. --- practice-tdd/repeat-str.test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js index 3587cf314..5905870ba 100644 --- a/practice-tdd/repeat-str.test.js +++ b/practice-tdd/repeat-str.test.js @@ -38,6 +38,17 @@ test("should return an empty string", () => { expect(repeatedStr).toEqual(""); }); +// Case: Handle empty string input: +// Given a target empty string `str` and a `count` equal to 1, +// When the repeatStr function is called with these inputs, +// Then it should return an empty string. +test("should return an empty string", () => { + const str = ""; + const count = 1; + 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,