Skip to content

Commit b6f5013

Browse files
removed redundant and unreachable codes from the files
1 parent b31a586 commit b6f5013

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ let testName = "Jerry";
55
const greeting = "hello";
66

77
function sayHello(greeting, name) {
8-
const greetingStr = greeting + ", " + name + "!";
8+
// const greetingStr = greeting + ", " + name + "!"; this line will also be removed because the we're trying to return something else, not the greetingStr and apparently it is a redundant code
99
return `${greeting}, ${name}!`;
10-
console.log(greetingStr);
10+
// console.log(greetingStr); this line will obviously be omitted as it is unreachable code because it is written after return. In fact, anything after return is not reachable and should be get ridden of
1111
}
1212

13-
testName = "Aman";
14-
1513
const greetingMessage = sayHello(greeting, testName);
16-
17-
console.log(greetingMessage); // 'hello, Aman!'
14+
console.log(greetingMessage);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
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());
5+
// const capitalisedPets = pets.map((pet) => pet.toUpperCase()); -- is obviously redundant code as it also writtend inside the function countAndCapitalisePets and should be removed
66
const petsStartingWithH = pets.filter((pet) => pet[0] === "h");
77

8-
function logPets(petsArr) {
9-
petsArr.forEach((pet) => console.log(pet));
8+
/* function logPets(petsArr) {
9+
petsArr.forEach((pet) => console.log(pet)); -- is also unnecessarily unused code and should also be removed
1010
}
11+
*/
1112

1213
function countAndCapitalisePets(petsArr) {
1314
const petCount = {};

0 commit comments

Comments
 (0)