From a3b92600682c8dbd4a01f26f48b4de3cc25a0950 Mon Sep 17 00:00:00 2001
From: d-odumosu
Date: Sun, 19 Jul 2026 19:34:33 +0100
Subject: [PATCH 1/4] completed jest testing on count test and implemented the
function
---
Sprint-3/2-practice-tdd/count.js | 17 +++++++++++++++--
Sprint-3/2-practice-tdd/count.test.js | 8 ++++++++
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js
index 95b6ebb7d4..e1566604ce 100644
--- a/Sprint-3/2-practice-tdd/count.js
+++ b/Sprint-3/2-practice-tdd/count.js
@@ -1,5 +1,18 @@
function countChar(stringOfCharacters, findCharacter) {
- return 5
-}
+ if(stringOfCharacters === "" || findCharacter === ""){
+ throw new Error("string an char are not given")
+ }
+
+ const str = stringOfCharacters.split("")
+ let count = 0;
+ for(const char of str){
+ if(char === findCharacter){
+ count++
+ }
+ }
+ return count
+}
+countChar("aeioyuyuuiiiiu", "i")
module.exports = countChar;
+//push char into a new array and count the lenght on new array return the lenght
\ No newline at end of file
diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js
index 179ea0ddf7..59f5d6ed34 100644
--- a/Sprint-3/2-practice-tdd/count.test.js
+++ b/Sprint-3/2-practice-tdd/count.test.js
@@ -19,6 +19,14 @@ test("should count multiple occurrences of a character", () => {
// Scenario: No Occurrences
// Given the input string `str`,
+
// And a character `char` that does not exist within `str`.
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of `char` were found.
+
+test("should return 0 when no occurrence of the char", () => {
+ const str = "aeiou";
+ const char = "b";
+ const count = countChar(str, char);
+ expect(count).toEqual(0);
+})
\ No newline at end of file
From d85efd8938a8636bb17f04d5a015bc7afe006efb Mon Sep 17 00:00:00 2001
From: d-odumosu
Date: Sun, 19 Jul 2026 22:17:22 +0100
Subject: [PATCH 2/4] completed jest testing on ordinal numbers and implemented
the function
---
Sprint-3/2-practice-tdd/get-ordinal-number.js | 28 ++++++++++++++-
.../2-practice-tdd/get-ordinal-number.test.js | 34 +++++++++++++++++--
2 files changed, 58 insertions(+), 4 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..a97a0ad9fe 100644
--- a/Sprint-3/2-practice-tdd/get-ordinal-number.js
+++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js
@@ -1,5 +1,31 @@
function getOrdinalNumber(num) {
- return "1st";
+ const numberStr1 = String(num).slice(-1)
+ const numberStr2 = String(num).slice(-2)
+
+ let number1 = Number(numberStr1)
+ let number2 = Number(numberStr2)
+
+ if (number2 === 11 || number2 === 12 || number2 === 13) {
+ return `${num}th`
+ }
+ else {
+
+ switch (number1) {
+ case 1:
+ return`${num}st`
+ break;
+ case 2:
+ return `${num}nd`
+ break;
+ case 3:
+ return `${num}rd`
+ break;
+ default:
+ return`${num}th`;
+ }
+ }
+
}
+
module.exports = getOrdinalNumber;
diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js
index adfa58560f..f4ecee3cbd 100644
--- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js
+++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js
@@ -14,7 +14,35 @@ const getOrdinalNumber = require("./get-ordinal-number");
// When the number ends with 1, except those ending with 11,
// Then the function should return a string by appending "st" to the number.
test("should append 'st' for numbers ending with 1, except those ending with 11", () => {
- expect(getOrdinalNumber(1)).toEqual("1st");
- expect(getOrdinalNumber(21)).toEqual("21st");
- expect(getOrdinalNumber(131)).toEqual("131st");
+ expect(getOrdinalNumber(1)).toEqual("1st");
+ expect(getOrdinalNumber(21)).toEqual("21st");
+ expect(getOrdinalNumber(131)).toEqual("131st");
});
+
+test("should append 'nd' for numbers ending with 2", () => {
+expect(getOrdinalNumber(2)).toEqual("2nd");
+expect(getOrdinalNumber(22)).toEqual("22nd");
+expect(getOrdinalNumber(32)).toEqual("32nd");
+
+});
+
+test("should append 'rd' for numbers ending with 3", () => {
+expect(getOrdinalNumber(3)).toEqual("3rd");
+expect(getOrdinalNumber(333)).toEqual("333rd");
+expect(getOrdinalNumber(303)).toEqual("303rd");
+
+});
+
+test("should append 'th' to numbers ending in 0, 4, 5, 6, 7, 8, 9, and to 11, 12, and 13", () => {
+expect(getOrdinalNumber(0)).toEqual("0th");
+expect(getOrdinalNumber(44)).toEqual("44th");
+expect(getOrdinalNumber(65)).toEqual("65th");
+expect(getOrdinalNumber(46)).toEqual("46th");
+expect(getOrdinalNumber(77)).toEqual("77th");
+expect(getOrdinalNumber(98)).toEqual("98th");
+expect(getOrdinalNumber(99)).toEqual("99th");
+expect(getOrdinalNumber(11)).toEqual("11th");
+expect(getOrdinalNumber(12)).toEqual("12th");
+expect(getOrdinalNumber(13)).toEqual("13th");
+})
+;
\ No newline at end of file
From 248d2a4d18a5fff87a3d4d7b8cfce6fb098ead43 Mon Sep 17 00:00:00 2001
From: d-odumosu
Date: Mon, 20 Jul 2026 20:01:46 +0100
Subject: [PATCH 3/4] completed jest testing o and implemented the function as
required
---
Sprint-3/2-practice-tdd/repeat-str.js | 27 ++++++++++++++++++----
Sprint-3/2-practice-tdd/repeat-str.test.js | 19 +++++++++++++++
2 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js
index 2af0a2cea7..018ae74e58 100644
--- a/Sprint-3/2-practice-tdd/repeat-str.js
+++ b/Sprint-3/2-practice-tdd/repeat-str.js
@@ -1,7 +1,24 @@
-function repeatStr() {
- // Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat).
- // The goal is to re-implement that function, not to use it.
- return "hellohellohello";
-}
+function repeatStr(word, wordCounter) {
+ // Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat).
+ // The goal is to re-implement that function, not to use it.
+ let count = 0;
+ let repeatedString = []
+ if (wordCounter < 0) { // rejects negative numbers
+ throw new Error("Enter a positive number")
+ }
+ if(wordCounter === 0){
+ return ""
+ }
+ if(wordCounter === 1){
+ return word
+ }
+ if(wordCounter > 1){
+ while(count < wordCounter){
+ count++
+ repeatedString.push(word)
+ }
+ }
+return repeatedString.join("")
+}
module.exports = repeatStr;
diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js
index a3fc1196c4..ede05fd676 100644
--- a/Sprint-3/2-practice-tdd/repeat-str.test.js
+++ b/Sprint-3/2-practice-tdd/repeat-str.test.js
@@ -20,13 +20,32 @@ test("should repeat the string count times", () => {
// Given a target string `str` and a `count` equal to 1,
// When the repeatStr function is called with these inputs,
// Then it should return the original `str` without repetition.
+test("should repeat the string 1 time", () =>{
+ const str = "name";
+ const count = 1;
+ const repeatedStr = repeatStr(str, count);
+ expect(repeatedStr).toEqual("name")
+})
// Case: Handle count of 0:
// Given a target string `str` and a `count` equal to 0,
// When the repeatStr function is called with these inputs,
// Then it should return an empty string.
+test("should return an empty string", () =>{
+ const str = "name";
+ const count = 0;
+ const repeatedStr = repeatStr(str, count);
+ expect(repeatedStr).toEqual("")
+})
// Case: Handle negative count:
// Given a target string `str` and a negative integer `count`,
// When the repeatStr function is called with these inputs,
// Then it should throw an error, as negative counts are not valid.
+// Case: Handle negative count:
+// Given a target string `str` and a negative integer `count`,
+// When the repeatStr function is called with these inputs,
+// Then it should throw an error, as negative counts are not valid.
+test("throws on negative number", () => {
+ expect(() => repeatStr("dami",-5)).toThrow("Enter a positive number");
+});
From f641d304b3dc96e7c4b9ec81e26fa60032117853 Mon Sep 17 00:00:00 2001
From: d-odumosu
Date: Mon, 20 Jul 2026 20:02:16 +0100
Subject: [PATCH 4/4] all requirements completed
---
Sprint-3/2-practice-tdd/count.js | 3 ---
1 file changed, 3 deletions(-)
diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js
index e1566604ce..4cb3a8c40d 100644
--- a/Sprint-3/2-practice-tdd/count.js
+++ b/Sprint-3/2-practice-tdd/count.js
@@ -11,8 +11,5 @@ function countChar(stringOfCharacters, findCharacter) {
}
}
return count
-
}
-countChar("aeioyuyuuiiiiu", "i")
module.exports = countChar;
-//push char into a new array and count the lenght on new array return the lenght
\ No newline at end of file