From c59a1ec7b746339be69042ef72b248313f260906 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 29 Mar 2026 16:44:25 +0100 Subject: [PATCH 1/5] implemented a function to count a character repeat --- Sprint-3/2-practice-tdd/count.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..a7310ad346 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,8 @@ -function countChar(stringOfCharacters, findCharacter) { - return 5 +function countChar(str, char) { + + return str.split(char).length -1; } -module.exports = countChar; +console.log(countChar('lol', 'l')); + +module.exports = countChar; \ No newline at end of file From df1e7bd0d918cbfa4847329286cb686675cf5cac Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 29 Mar 2026 16:46:22 +0100 Subject: [PATCH 2/5] implement a function to get the ordinal number for different ordinal cases. --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..8613add937 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,11 @@ -function getOrdinalNumber(num) { - return "1st"; +function getOrdinalNumber(n) { + if (n % 100 >= 11 && n % 100 <= 13) return n + "th"; + + if (n % 10 === 1) return n + "st"; + if (n % 10 === 2) return n + "nd"; + if (n % 10 === 3) return n + "rd"; + + return n + "th"; } module.exports = getOrdinalNumber; From 00f4fb9c13e8fa6939b5665309d7768f1f7ff369 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 29 Mar 2026 16:48:28 +0100 Subject: [PATCH 3/5] I wrote different test cases to handel repeating string for times more than 1, and to give empty out put for (0) and 'invalid count' output for negative counts. --- Sprint-3/2-practice-tdd/repeat-str.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b003..e74db07ce5 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,7 @@ -function repeatStr() { - return "hellohellohello"; -} +function repeatStr(str, count) { + if( count >= 0 ) + {return str.repeat (count)}; +else { return 'invalid count'}; +}; module.exports = repeatStr; From cd2f592035f9aa959d4de4533182c43b4690fbba Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 29 Mar 2026 16:50:10 +0100 Subject: [PATCH 4/5] I removed the console.log (greetingStr) code because it is unreachable code. - deleted the const greetingStr = greeting + ", " + name + "!"; because it is a redundant code that repeated already int the return function. --- Sprint-3/3-dead-code/exercise-1.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js index 4d09f15fa9..2425c454dd 100644 --- a/Sprint-3/3-dead-code/exercise-1.js +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -10,8 +10,4 @@ function sayHello(greeting, name) { console.log(greetingStr); } -testName = "Aman"; - -const greetingMessage = sayHello(greeting, testName); - -console.log(greetingMessage); // 'hello, Aman!' +testName = "Aman"; \ No newline at end of file From e0293c907232f4ce6b10e7d25852dc789fda30e1 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 29 Mar 2026 16:51:01 +0100 Subject: [PATCH 5/5] I removed the capitalisedPets variable as it unused code. aslo removed the logPets function as it doesn't called. --- Sprint-3/3-dead-code/exercise-2.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js index 56d7887c4c..b1c2362d34 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -2,13 +2,8 @@ // 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 = {};