Skip to content

Commit 84a56ad

Browse files
committed
refactored and cleaned dead code
1 parent 59b0c40 commit 84a56ad

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* Original code:
3+
*
14
// Find the instances of unreachable and redundant code - remove them!
25
// The sayHello function should continue to work for any reasonable input it's given.
36
@@ -15,3 +18,22 @@ testName = "Aman";
1518
const greetingMessage = sayHello(greeting, testName);
1619
1720
console.log(greetingMessage); // 'hello, Aman!'
21+
*
22+
* End of code
23+
*/
24+
25+
// The sayHello function should continue to work for any reasonable input it's given.
26+
27+
let testName = "Jerry";
28+
const greeting = "hello";
29+
30+
function sayHello(greeting, name) {
31+
return `${greeting}, ${name}!`;
32+
}
33+
34+
testName = "Aman";
35+
36+
const greetingMessage = sayHello(greeting, testName);
37+
38+
console.log(greetingMessage); // 'hello, Aman!'
39+

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* Original file:
3+
*
14
// Remove the unused code that does not contribute to the final console log
25
// The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable.
36
@@ -26,3 +29,31 @@ function countAndCapitalisePets(petsArr) {
2629
const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH);
2730
2831
console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log
32+
*
33+
* End of file
34+
*/
35+
36+
// Remove the unused code that does not contribute to the final console log
37+
// The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable.
38+
39+
const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"];
40+
const petsStartingWithH = pets.filter((pet) => pet[0] === "h");
41+
42+
function countAndCapitalisePets(petsArr) {
43+
const petCount = {};
44+
45+
petsArr.forEach((pet) => {
46+
const capitalisedPet = pet.toUpperCase();
47+
if (petCount[capitalisedPet]) {
48+
petCount[capitalisedPet] += 1;
49+
} else {
50+
petCount[capitalisedPet] = 1;
51+
}
52+
});
53+
return petCount;
54+
}
55+
56+
const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH);
57+
58+
console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log
59+

0 commit comments

Comments
 (0)