Skip to content

Commit 60b6378

Browse files
refactor: remove dead and unreachable code in exercise-1 and exercise-2
1 parent 8f3450d commit 60b6378

2 files changed

Lines changed: 44 additions & 11 deletions

File tree

‎dead-code/exercise-1.js‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
// Find the instances of unreachable and redundant code - remove them!
22
// The sayHello function should continue to work for any reasonable input it's given.
33

4-
let testName = "Jerry";
4+
// let testName = "Jerry";
5+
// const greeting = "hello";
6+
7+
// function sayHello(greeting, name) {
8+
// const greetingStr = greeting + ", " + name + "!";
9+
// return `${greeting}, ${name}!`;
10+
// console.log(greetingStr);
11+
// }
12+
13+
// testName = "Aman";
14+
15+
// const greetingMessage = sayHello(greeting, testName);
16+
17+
// console.log(greetingMessage); // 'hello, Aman!'
18+
519
const greeting = "hello";
20+
const testName = "Aman";
621

722
function sayHello(greeting, name) {
8-
const greetingStr = greeting + ", " + name + "!";
923
return `${greeting}, ${name}!`;
10-
console.log(greetingStr);
1124
}
1225

13-
testName = "Aman";
14-
1526
const greetingMessage = sayHello(greeting, testName);
1627

1728
console.log(greetingMessage); // 'hello, Aman!'

‎dead-code/exercise-2.js‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
11
// Remove the unused code that does not contribute to the final console log
22
// The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable.
33

4+
// const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"];
5+
// const capitalisedPets = pets.map((pet) => pet.toUpperCase());
6+
// const petsStartingWithH = pets.filter((pet) => pet[0] === "h");
7+
8+
// function logPets(petsArr) {
9+
// petsArr.forEach((pet) => console.log(pet));
10+
// }
11+
12+
// function countAndCapitalisePets(petsArr) {
13+
// const petCount = {};
14+
15+
// petsArr.forEach((pet) => {
16+
// const capitalisedPet = pet.toUpperCase();
17+
// if (petCount[capitalisedPet]) {
18+
// petCount[capitalisedPet] += 1;
19+
// } else {
20+
// petCount[capitalisedPet] = 1;
21+
// }
22+
// });
23+
// return petCount;
24+
// }
25+
26+
// const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH);
27+
28+
// console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log
29+
30+
431
const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"];
5-
const capitalisedPets = pets.map((pet) => pet.toUpperCase());
632
const petsStartingWithH = pets.filter((pet) => pet[0] === "h");
733

8-
function logPets(petsArr) {
9-
petsArr.forEach((pet) => console.log(pet));
10-
}
11-
1234
function countAndCapitalisePets(petsArr) {
1335
const petCount = {};
1436

@@ -25,4 +47,4 @@ function countAndCapitalisePets(petsArr) {
2547

2648
const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH);
2749

28-
console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log
50+
console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 }

0 commit comments

Comments
 (0)