From b34e66c2f2c34dff22a6405bdd957ff3684f05f7 Mon Sep 17 00:00:00 2001 From: boladjebsoft Date: Fri, 13 Mar 2026 16:45:04 +0000 Subject: [PATCH 01/17] test count function --- Sprint-3/2-practice-tdd/count.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf7..3aa8945b7b 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,3 +22,10 @@ test("should count multiple occurrences of a character", () => { // 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 character is not found", () => { + const str = "codeyourfuture"; + const char = "b"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); From efc78a8bc2741e85e05a9a2bbe91c0a1d9e47b07 Mon Sep 17 00:00:00 2001 From: boladjebsoft Date: Fri, 13 Mar 2026 19:18:42 +0000 Subject: [PATCH 02/17] testing --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 1 + 1 file changed, 1 insertion(+) 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..4e53849ea0 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -13,6 +13,7 @@ const getOrdinalNumber = require("./get-ordinal-number"); // Case 1: Numbers ending with 1 (but not 11) // 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"); From 293e98ec417425a44874a74bcc893f5f2787377b Mon Sep 17 00:00:00 2001 From: boladjebsoft Date: Fri, 13 Mar 2026 19:22:14 +0000 Subject: [PATCH 03/17] test the function countchar --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 1 - 1 file changed, 1 deletion(-) 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 4e53849ea0..adfa58560f 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -13,7 +13,6 @@ const getOrdinalNumber = require("./get-ordinal-number"); // Case 1: Numbers ending with 1 (but not 11) // 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"); From edb4fe49be0296f374b8a4b4a373420ad5556eeb Mon Sep 17 00:00:00 2001 From: boladjebsoft Date: Fri, 13 Mar 2026 22:10:50 +0000 Subject: [PATCH 04/17] testing --- Sprint-3/2-practice-tdd/count.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 3aa8945b7b..2a84aaee01 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,7 +22,6 @@ test("should count multiple occurrences of a character", () => { // 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 character is not found", () => { const str = "codeyourfuture"; const char = "b"; From fc349abc4d3cebd5b313b1e71e371ac0f5c95e8b Mon Sep 17 00:00:00 2001 From: boladjebsoft Date: Fri, 13 Mar 2026 22:53:43 +0000 Subject: [PATCH 05/17] implement count function --- Sprint-3/2-practice-tdd/count.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..3513153773 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,12 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0; + let x = 0; + for (; x < stringOfCharacters.length; x++) { + if (stringOfCharacters[x] === findCharacter) { + count++; + } + } + return count; } module.exports = countChar; From eb8eddac5bebddcab18f3eaa5ec2d55ce1d759f7 Mon Sep 17 00:00:00 2001 From: boladjebsoft Date: Sat, 14 Mar 2026 00:28:50 +0000 Subject: [PATCH 06/17] test getOrdinalNumber function --- .../2-practice-tdd/get-ordinal-number.test.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) 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..3bbb780e26 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -18,3 +18,35 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); + +// Case 2: Numbers ending with 2 (but not 12) +// When the number ends with 2, except those ending with 12, +// Then the function should return a string by appending "nd" to the number. +test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(202)).toEqual("202nd"); + expect(getOrdinalNumber(1032)).toEqual("1032nd"); +}); + +// Case 3: Numbers ending with 3 (but not 13) +// When the number ends with 3, except those ending with 13, +// Then the function should return a string by appending "rd" to the number. +test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(2333)).toEqual("2333rd"); + expect(getOrdinalNumber(13453)).toEqual("13453rd"); +}); + +// Case 4: All other numbers +// When the number does not end with 1, 2, or 3 (except for the exceptions), +// Then the function should return a string by appending "th" to the number. +test("should append 'th' for all other numbers", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); + expect(getOrdinalNumber(100)).toEqual("100th"); + expect(getOrdinalNumber(1012)).toEqual("1012th"); + expect(getOrdinalNumber(1038)).toEqual("1038th"); +}); From 4b7064626f024fab8fb30aadcddd995fe43f4518 Mon Sep 17 00:00:00 2001 From: boladjebsoft Date: Sat, 14 Mar 2026 00:52:57 +0000 Subject: [PATCH 07/17] implement the function getOrdinalNumber --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..a0fccca23d 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,16 @@ function getOrdinalNumber(num) { - return "1st"; + if (num % 10 === 1 && num % 100 !== 11) { + // we also can use if (num[-1]===1 && num.slice(-2)!==11) + return num + "st"; + } else if (num % 10 === 2 && num % 100 !== 12) { + // we also can use if (num[-1]===2 && num.slice(-2)!==12) + return num + "nd"; + } else if (num % 10 === 3 && num % 100 !== 13) { + // we also can use if (num[-1]===3 && num.slice(-2)!==13) + return num + "rd"; + } else { + return num + "th"; + } } module.exports = getOrdinalNumber; From 3c69efb82e01e20eb41a0221439c4445cc916bb0 Mon Sep 17 00:00:00 2001 From: boladjebsoft Date: Sat, 14 Mar 2026 01:05:31 +0000 Subject: [PATCH 08/17] test the repeatStr function --- Sprint-3/2-practice-tdd/repeat-str.test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index a3fc1196c4..2d27704797 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -21,12 +21,34 @@ test("should repeat the string count times", () => { // When the repeatStr function is called with these inputs, // Then it should return the original `str` without repetition. +test("should return the original string when count is 1", () => { + const str = "djebsoft"; + const count = 1; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("djebsoft"); +}); + // 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 when count is 0", () => { + const str = "djebsoft"; + 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. + +test("should throw an error when count is negative", () => { + const str = "CYF"; + const count = -2; + expect(() => repeatStr(str, count)).toThrow( + "Count cannot be a negative integer" + ); +}); From 7661229ffa28adb06db5c9e5f225c2b869694938 Mon Sep 17 00:00:00 2001 From: boladjebsoft Date: Sat, 14 Mar 2026 01:18:42 +0000 Subject: [PATCH 09/17] implement repeatStr function --- Sprint-3/2-practice-tdd/repeat-str.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b003..342f8b748b 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,21 @@ -function repeatStr() { - return "hellohellohello"; +function repeatStr(str, count) { + if (count === 0) { + return ""; + } else if (count === 1) { + return str; + } else if (count > 1) { + return str.repeat(count); + } else { + throw new Error("Count cannot be a negative number"); + } } +// I can make the 3 valid cases in 1 case with the repeat method as folows: +// function repeatStr(str, count) { +// if (count >= 0) { +// return str.repeat(count); +// } else { +// throw new Error("Count cannot be a negative number"); +// } +// } module.exports = repeatStr; From 1c57e2b6b29c6f68382cd5037f5e770766997af9 Mon Sep 17 00:00:00 2001 From: boladjebsoft Date: Mon, 16 Mar 2026 15:47:49 +0000 Subject: [PATCH 10/17] fixed the loop --- Sprint-3/2-practice-tdd/count.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 3513153773..d59e425d6b 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,8 +1,7 @@ function countChar(stringOfCharacters, findCharacter) { let count = 0; - let x = 0; - for (; x < stringOfCharacters.length; x++) { - if (stringOfCharacters[x] === findCharacter) { + for (let i = 0; i < stringOfCharacters.length; i++) { + if (stringOfCharacters[i] === findCharacter) { count++; } } From 0e0c2f529b7b5eca20d30987bf3afac8ba79d34d Mon Sep 17 00:00:00 2001 From: boladjebsoft Date: Mon, 16 Mar 2026 15:55:03 +0000 Subject: [PATCH 11/17] created variables to store the values of repeatedly used expressions --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 8 +++++--- 1 file changed, 5 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 a0fccca23d..17a38bf476 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,11 +1,13 @@ function getOrdinalNumber(num) { - if (num % 10 === 1 && num % 100 !== 11) { + let remainder1 = num % 10; + let remainder2 = num % 100; + if (remainder1 === 1 && remainder2 !== 11) { // we also can use if (num[-1]===1 && num.slice(-2)!==11) return num + "st"; - } else if (num % 10 === 2 && num % 100 !== 12) { + } else if (remainder1 === 2 && remainder2 !== 12) { // we also can use if (num[-1]===2 && num.slice(-2)!==12) return num + "nd"; - } else if (num % 10 === 3 && num % 100 !== 13) { + } else if (remainder1 === 3 && remainder2 !== 13) { // we also can use if (num[-1]===3 && num.slice(-2)!==13) return num + "rd"; } else { From ca4e87b2d6ee84bcd7b830fcb1868b5b313c7954 Mon Sep 17 00:00:00 2001 From: boladjebsoft Date: Mon, 16 Mar 2026 16:25:57 +0000 Subject: [PATCH 12/17] made some changes to make the test more informative --- .../2-practice-tdd/get-ordinal-number.test.js | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) 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 3bbb780e26..3866dd679f 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -37,15 +37,26 @@ test("should append 'rd' for numbers ending with 3, except those ending with 13" expect(getOrdinalNumber(13453)).toEqual("13453rd"); }); -// Case 4: All other numbers -// When the number does not end with 1, 2, or 3 (except for the exceptions), +// Case 4: numbers ending with 11, 12, or 13 +// When the number ends with 11, 12, or 13, // Then the function should return a string by appending "th" to the number. -test("should append 'th' for all other numbers", () => { - expect(getOrdinalNumber(4)).toEqual("4th"); - expect(getOrdinalNumber(10)).toEqual("10th"); + +test("should append 'th' for numbers ending with 11, 12, or 13", () => { expect(getOrdinalNumber(11)).toEqual("11th"); expect(getOrdinalNumber(12)).toEqual("12th"); expect(getOrdinalNumber(13)).toEqual("13th"); +}); + +// Case 5: numbers that ends with 0, 4, 5, 6, 7, 8, or 9 +// When the number does not end with 1, 2, or 3 +// Then the function should return a string by appending "th" to the number. + +test("should append 'th' for all other numbers", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(11)).toEqual("115th"); + expect(getOrdinalNumber(12)).toEqual("126th"); + expect(getOrdinalNumber(13)).toEqual("137th"); expect(getOrdinalNumber(100)).toEqual("100th"); expect(getOrdinalNumber(1012)).toEqual("1012th"); expect(getOrdinalNumber(1038)).toEqual("1038th"); From 75c15af1fb68355a2540f647e5e9d56deaf08762 Mon Sep 17 00:00:00 2001 From: boladjebsoft Date: Mon, 16 Mar 2026 16:30:34 +0000 Subject: [PATCH 13/17] simplyfying the code by using the repeat methodand making --- Sprint-3/2-practice-tdd/repeat-str.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 342f8b748b..680351e681 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,9 +1,5 @@ function repeatStr(str, count) { - if (count === 0) { - return ""; - } else if (count === 1) { - return str; - } else if (count > 1) { + if (count >= 0) { return str.repeat(count); } else { throw new Error("Count cannot be a negative number"); From 02245dbfc29bffd4d0d5f798e4a0f1c196d3b2a7 Mon Sep 17 00:00:00 2001 From: boladjebsoft Date: Mon, 16 Mar 2026 17:28:07 +0000 Subject: [PATCH 14/17] renamed variables --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index 17a38bf476..c79ce5aee4 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,13 +1,13 @@ function getOrdinalNumber(num) { - let remainder1 = num % 10; - let remainder2 = num % 100; - if (remainder1 === 1 && remainder2 !== 11) { + let lastDigit = num % 10; + let lastTwoDigits = num % 100; + if (lastDigit === 1 && lastTwoDigits !== 11) { // we also can use if (num[-1]===1 && num.slice(-2)!==11) return num + "st"; - } else if (remainder1 === 2 && remainder2 !== 12) { + } else if (lastDigit === 2 && lastTwoDigits !== 12) { // we also can use if (num[-1]===2 && num.slice(-2)!==12) return num + "nd"; - } else if (remainder1 === 3 && remainder2 !== 13) { + } else if (lastDigit === 3 && lastTwoDigits !== 13) { // we also can use if (num[-1]===3 && num.slice(-2)!==13) return num + "rd"; } else { From 73e0c619a4b5fee029142519fc908db525c50463 Mon Sep 17 00:00:00 2001 From: boladjebsoft Date: Mon, 16 Mar 2026 17:36:21 +0000 Subject: [PATCH 15/17] fixed the comparison between a sting and a number to between two strings --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 6 +++--- 1 file changed, 3 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 c79ce5aee4..e67bbbae36 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -2,13 +2,13 @@ function getOrdinalNumber(num) { let lastDigit = num % 10; let lastTwoDigits = num % 100; if (lastDigit === 1 && lastTwoDigits !== 11) { - // we also can use if (num[-1]===1 && num.slice(-2)!==11) + // we also can use if (num[-1]==="1" && num.slice(-2)!=="11") return num + "st"; } else if (lastDigit === 2 && lastTwoDigits !== 12) { - // we also can use if (num[-1]===2 && num.slice(-2)!==12) + // we also can use if (num[-1]==="2" && num.slice(-2)!=="12") return num + "nd"; } else if (lastDigit === 3 && lastTwoDigits !== 13) { - // we also can use if (num[-1]===3 && num.slice(-2)!==13) + // we also can use if (num[-1]==="3" && num.slice(-2)!=="13") return num + "rd"; } else { return num + "th"; From 28288c3b1369715af9ffbef655b9ea437837f51b Mon Sep 17 00:00:00 2001 From: boladjebsoft Date: Mon, 16 Mar 2026 17:40:51 +0000 Subject: [PATCH 16/17] replacement jest output with the detailed conditions --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 3866dd679f..07725a67d2 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -48,10 +48,11 @@ test("should append 'th' for numbers ending with 11, 12, or 13", () => { }); // Case 5: numbers that ends with 0, 4, 5, 6, 7, 8, or 9 -// When the number does not end with 1, 2, or 3 +// When the number ends with 0, 4, 5, 6, 7, 8, or 9 // Then the function should return a string by appending "th" to the number. -test("should append 'th' for all other numbers", () => { +test("should append 'th' for numbers ending with 0, 4, 5, 6, 7, 8, or 9", () => { + expect(getOrdinalNumber(0)).toEqual("0th"); expect(getOrdinalNumber(4)).toEqual("4th"); expect(getOrdinalNumber(10)).toEqual("10th"); expect(getOrdinalNumber(11)).toEqual("115th"); From 756143057c180115ce1330dd9c5fa8ec6e200cac Mon Sep 17 00:00:00 2001 From: boladjebsoft Date: Mon, 16 Mar 2026 18:49:34 +0000 Subject: [PATCH 17/17] using .slice() instead of index to extract the last character --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 6 +++--- 1 file changed, 3 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 e67bbbae36..69f95eca24 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -2,13 +2,13 @@ function getOrdinalNumber(num) { let lastDigit = num % 10; let lastTwoDigits = num % 100; if (lastDigit === 1 && lastTwoDigits !== 11) { - // we also can use if (num[-1]==="1" && num.slice(-2)!=="11") + // we also can use if (num.slice(-1)==="1" && num.slice(-2)!=="11") return num + "st"; } else if (lastDigit === 2 && lastTwoDigits !== 12) { - // we also can use if (num[-1]==="2" && num.slice(-2)!=="12") + // we also can use if (num.slice(-1)==="2" && num.slice(-2)!=="12") return num + "nd"; } else if (lastDigit === 3 && lastTwoDigits !== 13) { - // we also can use if (num[-1]==="3" && num.slice(-2)!=="13") + // we also can use if (num.slice(-1)==="3" && num.slice(-2)!=="13") return num + "rd"; } else { return num + "th";