Skip to content

Commit e09b771

Browse files
authored
Clean up dead code in exercise-2.js
Removed unused variables and functions to clean up the code.
1 parent 822fa7a commit e09b771

1 file changed

Lines changed: 0 additions & 43 deletions

File tree

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

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,3 @@
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-
//let's start from top to bottom and logically think through each line
5-
6-
const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"];
7-
//above line is needed because it is used by everything else.
8-
9-
const capitalisedPets = pets.map((pet) => pet.toUpperCase());
10-
// i am removing above line as "capitalisedPets" is not used anywhere else.
11-
12-
const petsStartingWithH = pets.filter((pet) => pet[0] === "h");
13-
//this line is filters the words starting with "h" and is used later so we keep it.
14-
15-
function logPets(petsArr) {
16-
petsArr.forEach((pet) => console.log(pet));
17-
}
18-
//i am erasing the above function as "logPets" is not used anywhere else.
19-
20-
function countAndCapitalisePets(petsArr) {
21-
const petCount = {};
22-
//keeping this function, as petCount is used below.
23-
24-
petsArr.forEach((pet) => {
25-
const capitalisedPet = pet.toUpperCase();
26-
if (petCount[capitalisedPet]) {
27-
petCount[capitalisedPet] += 1;
28-
} else {
29-
petCount[capitalisedPet] = 1;
30-
}
31-
});
32-
return petCount;
33-
}
34-
//everything above is needed to count how many of each pets there are.
35-
36-
const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH);
37-
//it is used for function call, so needed.
38-
39-
console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log
40-
//we wanna see the result of our machinations so we keep it.
41-
42-
//THE FOLLOWING CODE IS THE CLEANED UP VERSION.
43-
441
const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"];
452

463
const petsStartingWithH = pets.filter((pet) => pet[0] === "h");

0 commit comments

Comments
 (0)