From 2ec464dbc48ff65549e7adba5c23cee37b311fe4 Mon Sep 17 00:00:00 2001 From: chefmatthaus-hub Date: Mon, 5 Oct 2026 16:38:51 +0200 Subject: [PATCH 1/6] Refactor time conversion logic and enhance test coverage for edge cases --- format-clock-edge-cases/timeConverter.js | 10 +++- format-clock-edge-cases/timeConverter.test.js | 48 ++++++++++++++++++- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 310c07bd9..95b539be7 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -1,11 +1,17 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); + const minutes = time.slice(2); + + if (hours === 24) { + return `12${minutes} am` + } if (hours > 12) { - return `${hours - 12}:00 pm`; + return `${hours - 12}${minutes} pm`; } + return `${time} am`; } -export {formatAs12HourClock}; +export {formatAs12HourClock}; \ No newline at end of file diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 88f2af094..95a7aa1c5 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -2,10 +2,54 @@ import {formatAs12HourClock} from "./timeConverter.js"; import assert from "node:assert"; import test from "node:test"; -test("correctly convert time after 12:00", function(){ +test("correctly convert hours after 12:00", () => { assert.equal(formatAs12HourClock("23:00"), "11:00 pm"); }); -test("can correctly convert morning time", function() { +test("correctly convert minutes after 12:00", () => { + assert.equal(formatAs12HourClock("23:53"), "11:53 pm"); +}); + +test("can correctly convert morning time", () => { assert.equal(formatAs12HourClock("08:00"), "08:00 am"); }); + +test("can correctly convert morning time minutes", () => { + assert.equal(formatAs12HourClock("08:30"), "08:30 am"); +}); + +test("can correctly convert morning time minutes", () => { + assert.equal(formatAs12HourClock("08:34"), "08:34 am"); +}); + +test("can successfully convert midnight time", () => + assert.equal(formatAs12HourClock("24:00"), "12:00 am")); + + + +/* +Edge cases: +Correctly convert hours after 12:00 +Input | Expected +23:00 11:00 pm + +Correctly convert afternoon hours and minutes +Input | Expected +23:00 11:53 pm + +Correctly convert morning time and minutes +Input | Expected +08:00 08:00 am + +Correctly convert morning time and minutes +Input | Expected +08:30 08:30 am + +Correctly convert morning time and minutes +Input | Expected +08:34 08:34 am + +Correctly convert midnight time +Input | Expected +24:00 12:00 am +*/ \ No newline at end of file From 0795731b4f4347e7ad275b61e3e24995418d827c Mon Sep 17 00:00:00 2001 From: chefmatthaus-hub Date: Wed, 7 Oct 2026 17:44:58 +0200 Subject: [PATCH 2/6] Refactor time conversion logic and add tests for edge cases including midnight and noon --- format-clock-edge-cases/timeConverter.js | 20 ++++++++---- format-clock-edge-cases/timeConverter.test.js | 32 +++++++++++++++++++ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 95b539be7..82c82a643 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -1,17 +1,23 @@ function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); - const minutes = time.slice(2); - if (hours === 24) { - return `12${minutes} am` + const [hoursStr, minutesStr] = time.split(':'); + const hours = Number(hoursStr); + const minutes = minutesStr; + + if (hours === 0 || hours === 24) { + return `12:${minutes} am` } - if (hours > 12) { - return `${hours - 12}${minutes} pm`; + if (hours === 12) { + return `12:${minutes} pm` } - return `${time} am`; + if (hours > 12) { + return `${hours - 12}:${minutes} pm`; + } + const formattedHours = String(hours).padStart(2, '0'); + return `${formattedHours}:${minutes} am`; } export {formatAs12HourClock}; \ No newline at end of file diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 95a7aa1c5..22ee9b448 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -25,7 +25,22 @@ test("can correctly convert morning time minutes", () => { test("can successfully convert midnight time", () => assert.equal(formatAs12HourClock("24:00"), "12:00 am")); +test("correctly convert midnight 00:00", () => { + assert.equal(formatAs12HourClock("00:00"), "12:00 am"); +}); + +test("correctly convert noon 12:00", () => { + assert.equal(formatAs12HourClock("12:00"), "12:00 pm"); +}); +test("correctly convert boundary time around noon", () => { + assert.equal(formatAs12HourClock("11:59"), "11:59 am"); + assert.equal(formatAs12HourClock("12:01"), "12:01 pm"); +}); + +test("correctly convert early afternoon hours", () => { + assert.equal(formatAs12HourClock("13:00"), "1:00 pm"); +}); /* Edge cases: @@ -52,4 +67,21 @@ Input | Expected Correctly convert midnight time Input | Expected 24:00 12:00 am + +Correctly convert midnight +Input | Expected +00:00 12:00 am + +Correctly convert noon +Input | Expected +12:00 12:00 pm + +Correctly convert boundary time around noon +Input | Expected +11:59 11:59 am +12:01 12:01 pm + +Correctly convert early afternoon hours +Input | Expected +13:00 1:00 pm */ \ No newline at end of file From 7753fc4912c98d0ca458f6795b624223c2416b7a Mon Sep 17 00:00:00 2001 From: chefmatthaus-hub Date: Wed, 7 Oct 2026 17:45:10 +0200 Subject: [PATCH 3/6] Enhance test coverage for single-digit morning hours in time conversion --- format-clock-edge-cases/timeConverter.js | 4 ++-- format-clock-edge-cases/timeConverter.test.js | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 82c82a643..7dc67c505 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -1,6 +1,5 @@ function formatAs12HourClock(time) { - - + const [hoursStr, minutesStr] = time.split(':'); const hours = Number(hoursStr); const minutes = minutesStr; @@ -16,6 +15,7 @@ function formatAs12HourClock(time) { if (hours > 12) { return `${hours - 12}:${minutes} pm`; } + const formattedHours = String(hours).padStart(2, '0'); return `${formattedHours}:${minutes} am`; } diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 22ee9b448..9420e6215 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -42,6 +42,10 @@ test("correctly convert early afternoon hours", () => { assert.equal(formatAs12HourClock("13:00"), "1:00 pm"); }); +test("correctly convert single-digit morning hours if supported", () => { + assert(formatAs12HourClock("08:30"), "8:30am"); +}); + /* Edge cases: Correctly convert hours after 12:00 @@ -84,4 +88,8 @@ Input | Expected Correctly convert early afternoon hours Input | Expected 13:00 1:00 pm + +Correctly convert single-digit morning hours if supported +Input | Expected +08:30 8:30 am */ \ No newline at end of file From f357b30a32dad2ede4156f4297517fe1b9f318e7 Mon Sep 17 00:00:00 2001 From: chefmatthaus-hub Date: Sat, 10 Oct 2026 18:52:58 +0200 Subject: [PATCH 4/6] Fix formatting issues in time conversion and update test assertions for single-digit morning hours --- format-clock-edge-cases/timeConverter.js | 7 ++++--- format-clock-edge-cases/timeConverter.test.js | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 7dc67c505..dd53f4e71 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -5,15 +5,16 @@ function formatAs12HourClock(time) { const minutes = minutesStr; if (hours === 0 || hours === 24) { - return `12:${minutes} am` + return `12:${minutes} am`; } if (hours === 12) { - return `12:${minutes} pm` + return `12:${minutes} pm`; } if (hours > 12) { - return `${hours - 12}:${minutes} pm`; + const formattedHours = String(hours - 12).padStart(2, '0'); + return `${formattedHours}:${minutes} pm`; } const formattedHours = String(hours).padStart(2, '0'); diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 9420e6215..a9608c505 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -39,11 +39,11 @@ test("correctly convert boundary time around noon", () => { }); test("correctly convert early afternoon hours", () => { - assert.equal(formatAs12HourClock("13:00"), "1:00 pm"); + assert.equal(formatAs12HourClock("13:00"), "01:00 pm"); }); test("correctly convert single-digit morning hours if supported", () => { - assert(formatAs12HourClock("08:30"), "8:30am"); + assert(formatAs12HourClock("08:30"), "08:30am"); }); /* From e2e47e3242d71ad89ca75ef6d72abd048770164c Mon Sep 17 00:00:00 2001 From: chefmatthaus-hub Date: Sun, 25 Oct 2026 17:25:19 +0200 Subject: [PATCH 5/6] Refactor sayHello function and update testName variable for clarity --- dead-code/exercise-1.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/dead-code/exercise-1.js b/dead-code/exercise-1.js index 4d09f15fa..f0187afed 100644 --- a/dead-code/exercise-1.js +++ b/dead-code/exercise-1.js @@ -1,17 +1,9 @@ -// 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"; +let testName = "Aman"; 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!' From ca2733506640d74bd6cd7927516578503c8e8a37 Mon Sep 17 00:00:00 2001 From: chefmatthaus-hub Date: Sun, 25 Oct 2026 17:36:10 +0200 Subject: [PATCH 6/6] Remove unused code and streamline pet filtering logic --- dead-code/exercise-2.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/dead-code/exercise-2.js b/dead-code/exercise-2.js index 56d7887c4..c85731369 100644 --- a/dead-code/exercise-2.js +++ b/dead-code/exercise-2.js @@ -1,17 +1,9 @@ -// Remove the unused code that does not contribute to the final console log -// 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)); -} +const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); function countAndCapitalisePets(petsArr) { const petCount = {}; - petsArr.forEach((pet) => { const capitalisedPet = pet.toUpperCase(); if (petCount[capitalisedPet]) {