Skip to content

Commit 83bf403

Browse files
committed
fix remove dead code
1 parent a969de2 commit 83bf403

2 files changed

Lines changed: 2 additions & 9 deletions

File tree

Sprint-3/3-dead-code/exercise-1.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
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"; -> we can initialize the variable without giving it a value because the testName is being reassigned later in the code. The value "Jerry" never appears in a function call.
4+
let testName;
55
const greeting = "hello";
66

77
function sayHello(greeting, name) {
8-
// const greetingStr = greeting + ", " + name + "!"; -> this line is not necessary because the returned string accomplishes the same thing, and the greetingStr is never being used. So it is redundant code and can be removed.
98
return `${greeting}, ${name}!`;
10-
// console.log(greetingStr); -> this line is never being executed because it comes after the return statement, so it never runs and can be removed.
119
}
1210

1311
testName = "Aman";

Sprint-3/3-dead-code/exercise-2.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22
// The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable.
33

44
const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"];
5-
// const capitalisedPets = pets.map((pet) => pet.toUpperCase()); -> this line is not necessary because the same functionality is implemented inside the function countAndCapitalisePets.
6-
// Also, the variable capitalisedPets in not being used in the global scope
7-
const petsStartingWithH = pets.filter((pet) => pet[0] === "h");
85

9-
// function logPets(petsArr) {
10-
// petsArr.forEach((pet) => console.log(pet));
11-
// } -> This function is not being used/called anywhere in the program, it is redundant code and should be removed.
6+
const petsStartingWithH = pets.filter((pet) => pet[0] === "h");
127

138
function countAndCapitalisePets(petsArr) {
149
const petCount = {};

0 commit comments

Comments
 (0)