Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
301ea63
List edge cases for test.
Sep 28, 2026
2501561
Update list.
Sep 28, 2026
63e477b
Add an if condition to check midnight
Sep 28, 2026
a8e1b2d
Add another case to test midnight
Sep 28, 2026
9e2cef8
Add test case 00:01 to 12:01 am
Sep 28, 2026
2ba2e34
Add condition for checking midday 12 pm
Sep 28, 2026
06d5f91
Add test case for 01:00 to 01:00 am
Sep 28, 2026
3dc6da6
Add test case for 11:59 to 11:59 am
Sep 28, 2026
1e6cb55
Add test case for 12:01 to 12:01 pm
Sep 28, 2026
61b2ce7
Add test case for 13:00 to 1:00 pm
Sep 28, 2026
0407869
Add test case fo 23:59 to 11:59 pm
Sep 28, 2026
06d3f9a
Add padStart method to hours
Sep 28, 2026
598f744
Add more description.
Sep 28, 2026
e6fde3b
Add padStart method to convert 23:00 to 01:00pm
Sep 29, 2026
c2f743c
Edit comments
Sep 29, 2026
e7ff9c7
Inline code directly into return statement
Sep 30, 2026
751fb78
Change am and pm to lower case and update description.
Sep 30, 2026
4707f5a
Unreachable code.
Sep 30, 2026
f504687
Remove unreachable and redundant code.
Sep 30, 2026
d9197c4
Remove unused code
Sep 30, 2026
9494c3d
Update function to work for any input.
Sep 30, 2026
582699c
Format code with prettier.
Sep 30, 2026
b806b41
Stop tracking files
Oct 3, 2026
fcf27e7
Stop tracking files
Oct 3, 2026
04f544f
Restore files unrelated to this PR
Oct 3, 2026
3931817
Add console.log()
russom-g Oct 22, 2026
f9cb199
Remove redundant const pets variable.
russom-g Oct 22, 2026
f920355
Refactor code.
russom-g Oct 22, 2026
05a9485
Fix code to print 'hello Aman'
russom-g Oct 29, 2026
a3ec00c
Update code to work for any input given.
russom-g Oct 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions dead-code/exercise-1.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
// 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);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Run node dead-code/exercise-1.js on main and on your branch. What does each print? Dead code is code that never affects the output, so was console.log(greetingMessage) dead?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I made the sayHello function to continue to work for any reasonable input it's given.

I added a console.log() now

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The log is back, thanks. Run node dead-code/exercise-1.js now: it prints Hi, Aman!, but main prints hello, Aman!. Where does the Hi on line 8 come from, and what did the starter pass in as the greeting?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I fixed the problem


testName = "Aman";

const greetingMessage = sayHello(greeting, testName);

console.log(greetingMessage); // 'hello, Aman!'
console.log(greetingMessage);
12 changes: 4 additions & 8 deletions dead-code/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@
// 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"];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where is pets used now?

@russom-g russom-g Oct 22, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I misunderstood the instruction. It is fixed now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed, pets is used again and unchanged.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

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;
}
});

return petCount;
}

const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH);
const petsStartingWithH = pets.filter((pet) => pet[0] === "h");

console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log
console.log(countAndCapitalisePets(petsStartingWithH));
Loading