From bf34f104be4f774e0f002692c21679b2a600bf4e Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Thu, 12 Nov 2026 05:51:39 +0000 Subject: [PATCH 1/7] Remove redundant code --- dead-code/exercise-1.js | 1 - 1 file changed, 1 deletion(-) diff --git a/dead-code/exercise-1.js b/dead-code/exercise-1.js index 4d09f15fa9..3d0a8bed26 100644 --- a/dead-code/exercise-1.js +++ b/dead-code/exercise-1.js @@ -5,7 +5,6 @@ let testName = "Jerry"; const greeting = "hello"; function sayHello(greeting, name) { - const greetingStr = greeting + ", " + name + "!"; return `${greeting}, ${name}!`; console.log(greetingStr); } From d438afa54bcf214091cf1fe4a0a7fc4b0c76f67c Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Thu, 12 Nov 2026 05:55:20 +0000 Subject: [PATCH 2/7] Removed unreachable code --- dead-code/exercise-1.js | 1 - 1 file changed, 1 deletion(-) diff --git a/dead-code/exercise-1.js b/dead-code/exercise-1.js index 3d0a8bed26..5de7eb4ba7 100644 --- a/dead-code/exercise-1.js +++ b/dead-code/exercise-1.js @@ -6,7 +6,6 @@ const greeting = "hello"; function sayHello(greeting, name) { return `${greeting}, ${name}!`; - console.log(greetingStr); } testName = "Aman"; From 2114d7059270fc4d5adc2c22141112a23c59f5c5 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Thu, 12 Nov 2026 06:02:46 +0000 Subject: [PATCH 3/7] Removed unsued variable --- dead-code/exercise-2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dead-code/exercise-2.js b/dead-code/exercise-2.js index 56d7887c4c..0b4e76239a 100644 --- a/dead-code/exercise-2.js +++ b/dead-code/exercise-2.js @@ -2,7 +2,7 @@ // 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) { From e5baf351877e86d0218e2c7bdd47842a6f37ec95 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Thu, 12 Nov 2026 06:06:23 +0000 Subject: [PATCH 4/7] Removed unused function --- dead-code/exercise-2.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dead-code/exercise-2.js b/dead-code/exercise-2.js index 0b4e76239a..1d292f2f8c 100644 --- a/dead-code/exercise-2.js +++ b/dead-code/exercise-2.js @@ -5,10 +5,6 @@ const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); -function logPets(petsArr) { - petsArr.forEach((pet) => console.log(pet)); -} - function countAndCapitalisePets(petsArr) { const petCount = {}; From 6366b00b9ae98c2bb95bd816d737f48b5446624e Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Thu, 12 Nov 2026 06:47:32 +0000 Subject: [PATCH 5/7] Add countChar edge case tests --- practice-tdd/count.js | 9 ++++++++- practice-tdd/count.test.js | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/practice-tdd/count.js b/practice-tdd/count.js index 5518c57123..0b461dfd4b 100644 --- a/practice-tdd/count.js +++ b/practice-tdd/count.js @@ -1,3 +1,10 @@ export function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0; + + for (const character of stringOfCharacters) { + if (character === findCharacter) { + count++; + } + } + return count; } diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index cb3aaae591..20076ab98a 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -17,6 +17,15 @@ test("should count multiple occurrences of a character", () => { expect(count).toEqual(5); }); +test("should count occurrences in a mixed string", () => { + const count = countChar("banana", "a"); + expect(count).toEqual(3); +}); + +test("should return 0 for an empty string", () => { + const count = countChar("", "a"); + expect(count).toEqual(0); +}); // Scenario: No Occurrences // Given the input string `str`, // And a character `char` that does not exist within `str`. From 89c6ae89240459ca443b27d251b768df485b13ac Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Thu, 12 Nov 2026 06:55:43 +0000 Subject: [PATCH 6/7] Add missing countChart test --- practice-tdd/count.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index 20076ab98a..b9c70b3f68 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -26,6 +26,12 @@ test("should return 0 for an empty string", () => { const count = countChar("", "a"); expect(count).toEqual(0); }); + +test("should return 0 when character does not occur", () => { + const count = countChar("hello", "z"); + expect(count).toEqual(0); +}); + // Scenario: No Occurrences // Given the input string `str`, // And a character `char` that does not exist within `str`. From 7da20a13ebc61965f7eb9c2d11eb3e3a35fa4868 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Thu, 12 Nov 2026 07:22:33 +0000 Subject: [PATCH 7/7] Remove redundant testName assigment --- dead-code/exercise-1.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dead-code/exercise-1.js b/dead-code/exercise-1.js index 5de7eb4ba7..209fadc9b8 100644 --- a/dead-code/exercise-1.js +++ b/dead-code/exercise-1.js @@ -1,15 +1,13 @@ // 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"; +let testName = "Aman"; const greeting = "hello"; function sayHello(greeting, name) { return `${greeting}, ${name}!`; } -testName = "Aman"; - const greetingMessage = sayHello(greeting, testName); console.log(greetingMessage); // 'hello, Aman!'