Skip to content

Commit f89a0f5

Browse files
committed
Merge branch 'main' of https://github.com/CodeYourFuture/Module-Data-Flows into praj-deadcode-backlog
2 parents 34ed05d + 24265bc commit f89a0f5

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

Sprint-3/dead-code/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Refactoring Dead Code
2+
3+
Here are two example of code that has not been built efficiently. Both files have dead code in them. It's your job to go back through this existing code, identify the dead code, and remove it so the code is ready for production.
4+
5+
## Instructions
6+
7+
1. Work through each `exercise` file inside this directory.
8+
2. Delete the dead code.
9+
3. Commit your changes and make a PR when done.

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Find the instances of unreachable and redundant code - remove them!
2+
// The sayHello function should continue to work for any reasonable input it's given.
3+
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!'

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Remove the unused code that does not contribute to the final console log
2+
// The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable.
3+
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

0 commit comments

Comments
 (0)