From 6fac035aa3ee903a71f22af4cb0cdc097683a45a Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 29 Mar 2026 17:04:09 +0100 Subject: [PATCH 1/3] 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 1dbf4e370f5be6407f155c8b4f3e6d088f0ac502 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 29 Mar 2026 17:04:39 +0100 Subject: [PATCH 2/3] implement a function to get the ordinal number for different ordinal cases. --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 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..def003de77 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; +module.exports = getOrdinalNumber; \ No newline at end of file From e21abf0c0792431300bbd09bdc599bf18e3d0658 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 29 Mar 2026 17:05:14 +0100 Subject: [PATCH 3/3] 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 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b003..c6e2f8dddd 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; +module.exports = repeatStr; \ No newline at end of file