Skip to content

Cape Town | sep-2026-ITP | Matthaus Bause | Sprint 3 | Dead Code - #1755

Open
chefmatthaus-hub wants to merge 6 commits into
CodeYourFuture:mainfrom
chefmatthaus-hub:coursework/sprint-3-dead-code
Open

chefmatthaus-hub wants to merge 6 commits into
CodeYourFuture:mainfrom
chefmatthaus-hub:coursework/sprint-3-dead-code

Conversation

@chefmatthaus-hub

Copy link
Copy Markdown

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

CYF-1006

@chefmatthaus-hub chefmatthaus-hub added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 25, 2026
@mayowaolokun mayowaolokun added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 25, 2026

@mayowaolokun mayowaolokun left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread dead-code/exercise-1.js
// The sayHello function should continue to work for any reasonable input it's given.

let testName = "Jerry";
let testName = "Aman";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment on lines +11 to +21
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`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment on lines +45 to +47
test("correctly convert single-digit morning hours if supported", () => {
assert(formatAs12HourClock("08:30"), "08:30am");
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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", () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +25 to +26
test("can successfully convert midnight time", () =>
assert.equal(formatAs12HourClock("24:00"), "12:00 am"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the comment on line R24 as it applies here.

@mayowaolokun mayowaolokun added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants