Repository navigation
Cape Town | sep-2026-ITP | Matthaus Bause | Sprint 3 | Dead Code - #1755
chefmatthaus-hub wants to merge 6 commits into
Conversation
… midnight and noon
…or single-digit morning hours
mayowaolokun
left a comment
There was a problem hiding this comment.
Great work, you clearly understand how to spot unused and unreachable code, and your formatAs12HourClock fix handles the edge cases correctly, including midnight, noon and times with minutes. Planning your edge cases before writing the tests was a really good approach.
I have left a few comments. Mainly on lines 45–47 of timeConverter.test.js, as it may not be checking what you expect. The rest are tidy-ups around consistency, duplicate test names and file formatting.
You’re very close. Once those are addressed, this will be in great shape.
| // The sayHello function should continue to work for any reasonable input it's given. | ||
|
|
||
| let testName = "Jerry"; | ||
| let testName = "Aman"; |
There was a problem hiding this comment.
Nice work spotting the unreachable console.log and the unused greetingStr, and setting testName correctly from the start is a neat simplification. Since testName is no longer reassigned anywhere, have another look at how it’s declared and think about which keyword best signals that its value won’t change.
| @@ -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. | |||
|
|
|||
There was a problem hiding this comment.
Well done for removing capitalisedPets and logPets, and for keeping petsStartingWithH, which the final output depends on. Line 3 hasn’t changed, but because it has moved, Git shows it as deleted and re-added, so reviewers have to check that it wasn’t altered. When removing code, try to leave the remaining lines where they were so the diff shows only your intended changes. Checking your diff before pushing is a good way to catch this.
| } | ||
|
|
||
| export {formatAs12HourClock}; | ||
| export {formatAs12HourClock}; No newline at end of file |
There was a problem hiding this comment.
The icon here means the file no longer ends with a newline, which is why this unchanged line shows as modified. Most editors and tools expect files to end with a newline, so it’s worth checking your editor settings (Prettier on save should handle this for you).
| if (hours === 12) { | ||
| return `12:${minutes} pm`; | ||
| } | ||
|
|
||
| if (hours > 12) { | ||
| return `${hours - 12}:00 pm`; | ||
| const formattedHours = String(hours - 12).padStart(2, '0'); | ||
| return `${formattedHours}:${minutes} pm`; | ||
| } | ||
| return `${time} am`; | ||
|
|
||
| const formattedHours = String(hours).padStart(2, '0'); | ||
| return `${formattedHours}:${minutes} am`; |
There was a problem hiding this comment.
Great work handling the edge cases.
Since this task is about edge cases, make sure your tests cover them too, such as "00:00", "12:00", and a time with minutes like "13:45", so you can be confident that each branch works.
|
|
||
| const [hoursStr, minutesStr] = time.split(':'); | ||
| const hours = Number(hoursStr); | ||
| const minutes = minutesStr; |
There was a problem hiding this comment.
This line creates a second variable holding exactly the same value as minutesStr. Is there a way you could avoid the extra variable while keeping the code readable?
| test("correctly convert single-digit morning hours if supported", () => { | ||
| assert(formatAs12HourClock("08:30"), "08:30am"); | ||
| }); |
There was a problem hiding this comment.
This test uses assert(...) rather than assert.equal(...) like the others. Have a look at what the second argument to assert() actually does, and whether this test could ever fail. It’s also worth checking that the input matches the test name (is "08:30" a single-digit hour?) and that the expected output is formatted the same way as your other tests.
| assert.equal(formatAs12HourClock("08:30"), "08:30 am"); | ||
| }); | ||
|
|
||
| test("can correctly convert morning time minutes", () => { |
There was a problem hiding this comment.
This test has the same name as the one on line 17. Unique names make it much easier to tell which test failed when something breaks.
| test("can successfully convert midnight time", () => | ||
| assert.equal(formatAs12HourClock("24:00"), "12:00 am")); |
There was a problem hiding this comment.
This test is written differently from the others (no curly braces or semicolons). Keeping a consistent style makes the file easier to read.
|
|
||
| Correctly convert early afternoon hours | ||
| Input | Expected | ||
| 13:00 1:00 pm |
There was a problem hiding this comment.
The comment here expects 1:00 pm, but the test on line 42 expects 01:00 pm. Which format does your function produce? It’s worth making the comment and test agree so they don’t confuse.
| Correctly convert single-digit morning hours if supported | ||
| Input | Expected | ||
| 08:30 8:30 am | ||
| */ No newline at end of file |
There was a problem hiding this comment.
Check the comment on line R24 as it applies here.
Self checklist
CYF-1006