Skip to content

Commit bd742bc

Browse files
authored
Dead code backlog task migration (#904)
Addressing this issue: CodeYourFuture/curriculum#1670 Adding dead code backlog material that originally sat in Data Flows module. Corresponding backlog issue has been created: #903
1 parent 5dc9452 commit bd742bc

File tree

9 files changed

+57
-1
lines changed

9 files changed

+57
-1
lines changed

Sprint-3/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/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/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
File renamed without changes.
File renamed without changes.

Sprint-3/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
> Do the prep.
1010
1111
This sprint you are expected to produce multiple different pull requests:
12+
1213
1. One pull request for the `1-implement-and-rewrite-tests` directory.
1314
2. One pull request for the `2-practice-tdd` directory.
14-
3. Optionally, one pull request for the `3-stretch` directory.
15+
3. One pull request for the `3-dead-code` directory.
16+
4. Optionally, one pull request for the `4-stretch` directory.
1517

1618
Each directory contains a README.md file with instructions for that directory.

0 commit comments

Comments
 (0)