From 5fe338c8e7286a8b1f566c63237c616a362e5035 Mon Sep 17 00:00:00 2001 From: Poonam Rajput Date: Fri, 9 Jan 2026 14:34:42 +0000 Subject: [PATCH 1/2] Adding dead code backlog task --- Sprint-3/3-dead-code/README.md | 9 +++++++++ Sprint-3/3-dead-code/exercise-1.js | 17 +++++++++++++++++ Sprint-3/3-dead-code/exercise-2.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 Sprint-3/3-dead-code/README.md create mode 100644 Sprint-3/3-dead-code/exercise-1.js create mode 100644 Sprint-3/3-dead-code/exercise-2.js diff --git a/Sprint-3/3-dead-code/README.md b/Sprint-3/3-dead-code/README.md new file mode 100644 index 000000000..2bfbfff81 --- /dev/null +++ b/Sprint-3/3-dead-code/README.md @@ -0,0 +1,9 @@ +# Refactoring Dead Code + +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. + +## Instructions + +1. Work through each `exercise` file inside this directory. +2. Delete the dead code. +3. Commit your changes and make a PR when done. diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js new file mode 100644 index 000000000..4d09f15fa --- /dev/null +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -0,0 +1,17 @@ +// Find the instances of unreachable and redundant code - remove them! +// The sayHello function should continue to work for any reasonable input it's given. + +let testName = "Jerry"; +const greeting = "hello"; + +function sayHello(greeting, name) { + const greetingStr = greeting + ", " + name + "!"; + return `${greeting}, ${name}!`; + console.log(greetingStr); +} + +testName = "Aman"; + +const greetingMessage = sayHello(greeting, testName); + +console.log(greetingMessage); // 'hello, Aman!' diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js new file mode 100644 index 000000000..56d7887c4 --- /dev/null +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -0,0 +1,28 @@ +// Remove the unused code that does not contribute to the final console log +// The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. + +const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; +const capitalisedPets = pets.map((pet) => pet.toUpperCase()); +const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); + +function logPets(petsArr) { + petsArr.forEach((pet) => console.log(pet)); +} + +function countAndCapitalisePets(petsArr) { + const petCount = {}; + + petsArr.forEach((pet) => { + const capitalisedPet = pet.toUpperCase(); + if (petCount[capitalisedPet]) { + petCount[capitalisedPet] += 1; + } else { + petCount[capitalisedPet] = 1; + } + }); + return petCount; +} + +const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH); + +console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log From 9987ade9b575added958c4dc4d9d5c22ae888209 Mon Sep 17 00:00:00 2001 From: Poonam Rajput Date: Fri, 9 Jan 2026 14:35:01 +0000 Subject: [PATCH 2/2] reordering backlog tasks for sprint 3 due to added dead code work --- Sprint-3/{3-stretch => 4-stretch}/README.md | 0 Sprint-3/{3-stretch => 4-stretch}/card-validator.md | 0 Sprint-3/{3-stretch => 4-stretch}/find.js | 0 Sprint-3/{3-stretch => 4-stretch}/password-validator.js | 0 Sprint-3/{3-stretch => 4-stretch}/password-validator.test.js | 0 Sprint-3/readme.md | 4 +++- 6 files changed, 3 insertions(+), 1 deletion(-) rename Sprint-3/{3-stretch => 4-stretch}/README.md (100%) rename Sprint-3/{3-stretch => 4-stretch}/card-validator.md (100%) rename Sprint-3/{3-stretch => 4-stretch}/find.js (100%) rename Sprint-3/{3-stretch => 4-stretch}/password-validator.js (100%) rename Sprint-3/{3-stretch => 4-stretch}/password-validator.test.js (100%) diff --git a/Sprint-3/3-stretch/README.md b/Sprint-3/4-stretch/README.md similarity index 100% rename from Sprint-3/3-stretch/README.md rename to Sprint-3/4-stretch/README.md diff --git a/Sprint-3/3-stretch/card-validator.md b/Sprint-3/4-stretch/card-validator.md similarity index 100% rename from Sprint-3/3-stretch/card-validator.md rename to Sprint-3/4-stretch/card-validator.md diff --git a/Sprint-3/3-stretch/find.js b/Sprint-3/4-stretch/find.js similarity index 100% rename from Sprint-3/3-stretch/find.js rename to Sprint-3/4-stretch/find.js diff --git a/Sprint-3/3-stretch/password-validator.js b/Sprint-3/4-stretch/password-validator.js similarity index 100% rename from Sprint-3/3-stretch/password-validator.js rename to Sprint-3/4-stretch/password-validator.js diff --git a/Sprint-3/3-stretch/password-validator.test.js b/Sprint-3/4-stretch/password-validator.test.js similarity index 100% rename from Sprint-3/3-stretch/password-validator.test.js rename to Sprint-3/4-stretch/password-validator.test.js diff --git a/Sprint-3/readme.md b/Sprint-3/readme.md index 491afb81c..983e3b1ff 100644 --- a/Sprint-3/readme.md +++ b/Sprint-3/readme.md @@ -9,8 +9,10 @@ > Do the prep. This sprint you are expected to produce multiple different pull requests: + 1. One pull request for the `1-implement-and-rewrite-tests` directory. 2. One pull request for the `2-practice-tdd` directory. -3. Optionally, one pull request for the `3-stretch` directory. +3. As a stretch goal, one pull request for the `3-dead-code` directory. +4. Optionally, one pull request for the `4-stretch` directory. Each directory contains a README.md file with instructions for that directory.