Skip to content

Commit 6816c32

Browse files
committed
exercise-2.js committed
1 parent 20fcc14 commit 6816c32

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

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

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

0 commit comments

Comments
 (0)