From 447094d022e7a8dc07e822d8f44681bc25623125 Mon Sep 17 00:00:00 2001 From: Liban Jama Date: Fri, 6 Mar 2026 19:18:40 +0000 Subject: [PATCH 1/5] Completed count.js --- Sprint-3/2-practice-tdd/count.js | 15 ++++++++++++++- Sprint-3/2-practice-tdd/count.test.js | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..8c2e24f008 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 + // trying to find the amount of times the findCharacter is found in the stringOfCharacters + const lengthOfString = stringOfCharacters.length; + console.log("lengthOfString", lengthOfString); + + // replace all instances of findCharacter in string of characters with an empty string, and then get the length. (e.g. in house replace the e with an empty string " "). + const otherLettersLength = stringOfCharacters.replaceAll( + findCharacter, + "" + ).length; + + // declaring the variable called result and subtract otherLettersLength from the lengthOfString to find the number of occurences of findCharacter. + const result = lengthOfString - otherLettersLength; + console.log("result", result); + return result; } module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf7..3bec82b90d 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -17,8 +17,30 @@ test("should count multiple occurrences of a character", () => { expect(count).toEqual(5); }); +test("should count multiple occurrences of a character", () => { + const str = "house"; + const char = "e"; + const count = countChar(str, char); + expect(count).toEqual(1); +}); + +test("should count multiple occurrences of a character", () => { + const str = "playful"; + const char = "l"; + const count = countChar(str, char); + expect(count).toEqual(2); +}); + // 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(``); +test("should return when there are no occurrences of a character", () => { + const str = "spaceship"; + const char = "x"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); From b48a37b13681114d4ee4adb3dcf5db613cfe108b Mon Sep 17 00:00:00 2001 From: Liban Jama Date: Fri, 6 Mar 2026 19:20:27 +0000 Subject: [PATCH 2/5] Completed get-ordinal-number --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 15 ++++++++++++++- .../2-practice-tdd/get-ordinal-number.test.js | 12 ++++++++++++ 2 files changed, 26 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..793eab00bf 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,18 @@ function getOrdinalNumber(num) { - return "1st"; + const lastdigit = num % 10; + if (lastdigit === 1) { + return `${num}st`; + } + + if (lastdigit === 2) { + return `${num}nd`; + } + + if (lastdigit === 3) { + return `${num}rd`; + } else { + 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..d03bc31c74 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,15 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" 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(132)).toEqual("132nd"); +}); + +test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(33)).toEqual("33rd"); + expect(getOrdinalNumber(133)).toEqual("133rd"); +}); From 90db0f1f029a2c2094be18d91451bde0e9a454ba Mon Sep 17 00:00:00 2001 From: Liban Jama Date: Fri, 6 Mar 2026 19:24:49 +0000 Subject: [PATCH 3/5] Completed repeat-str --- Sprint-3/2-practice-tdd/repeat-str.js | 9 ++++++--- Sprint-3/2-practice-tdd/repeat-str.test.js | 21 +++++++++++++++++++++ 2 files changed, 27 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..630f39754e 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,8 @@ -function repeatStr() { - return "hellohellohello"; +function repeatStr(str, count) { + if (count < 0) { + throw new Error("invalid count"); + } + return str.repeat(count); } - +// call the repeat function on the string and pass in count. 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..bf8fb98008 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -21,12 +21,33 @@ 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 repeat the string count times", () => { + const str = "hello"; + const count = 1; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("hello"); +}); + // 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 repeat the string count times", () => { + const str = "hello"; + 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 repeat the string count times", () => { + const str = "hello"; + const count = -2; + // const repeatedStr = repeatStr(str, count); + expect(() => repeatStr(str, count)).toThrow("invalid count"); +}); From 34d7ce4278977aa3e8568ffd16663257356f62b0 Mon Sep 17 00:00:00 2001 From: Liban Jama Date: Fri, 13 Mar 2026 10:28:50 +0000 Subject: [PATCH 4/5] changed after feedback --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 15 +++++++ .../2-practice-tdd/get-ordinal-number.test.js | 39 +++++++++++++++++++ Sprint-3/2-practice-tdd/repeat-str.js | 21 ++++++++++ Sprint-3/2-practice-tdd/repeat-str.test.js | 11 ++++++ 4 files changed, 86 insertions(+) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index 793eab00bf..b65ddfc596 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,4 +1,5 @@ function getOrdinalNumber(num) { +<<<<<<< Updated upstream const lastdigit = num % 10; if (lastdigit === 1) { return `${num}st`; @@ -13,6 +14,20 @@ function getOrdinalNumber(num) { } else { return `${num}th`; } +======= + const lastDigit = num % 10; + const lastTwoDigits = num % 100; + + if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { + return num + "th"; + } + + if (lastDigit === 1) return num + "st"; + if (lastDigit === 2) return num + "nd"; + if (lastDigit === 3) return num + "rd"; + + return num + "th"; +>>>>>>> Stashed changes } 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 d03bc31c74..37918e326d 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -19,14 +19,53 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(131)).toEqual("131st"); }); +<<<<<<< Updated upstream test("should append 'nd' for numbers ending with 2", () => { +======= +// 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("Numbers ending with 2 (but not 12) should return 'nd'", () => { +>>>>>>> Stashed changes expect(getOrdinalNumber(2)).toEqual("2nd"); expect(getOrdinalNumber(22)).toEqual("22nd"); expect(getOrdinalNumber(132)).toEqual("132nd"); }); +<<<<<<< Updated upstream test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { expect(getOrdinalNumber(3)).toEqual("3rd"); expect(getOrdinalNumber(33)).toEqual("33rd"); expect(getOrdinalNumber(133)).toEqual("133rd"); }); +======= +// 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("Numbers ending with 3 (but not 13) should return 'rd'", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(133)).toEqual("133rd"); +}); + +// Case 4: Numbers ending with 0,4-9 +// 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("Numbers ending with 0,4-9 should return 'th'", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(25)).toEqual("25th"); +}); + +// Case 5: 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("Numbers ending with 11,12,13 should return 'th'", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); + expect(getOrdinalNumber(111)).toEqual("111th"); + expect(getOrdinalNumber(112)).toEqual("112th"); + expect(getOrdinalNumber(113)).toEqual("113th"); +}); +>>>>>>> Stashed changes diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 630f39754e..163d9a7414 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,8 +1,29 @@ function repeatStr(str, count) { if (count < 0) { +<<<<<<< Updated upstream throw new Error("invalid count"); } return str.repeat(count); +======= + throw new Error("Count cannot be negative"); + } + + if (count === 0) { + return ""; + } + + if (count === 1) { + return str; + } + + let result = ""; + + for (let i = 0; i < count; i++) { + result += str; + } + + return result; +>>>>>>> Stashed changes } // call the repeat function on the string and pass in count. 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 bf8fb98008..8c7d81ba65 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -20,6 +20,9 @@ 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("given a string and count of 1, returns the original string", () => { + expect(repeatStr("hello", 1)).toBe("hello"); +}); test("should repeat the string count times", () => { const str = "hello"; @@ -32,6 +35,9 @@ test("should repeat the string count times", () => { // 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("given a string and count of 0, returns an empty string", () => { + expect(repeatStr("hello", 0)).toBe(""); +}); test("should repeat the string count times", () => { const str = "hello"; @@ -44,10 +50,15 @@ test("should repeat the string count times", () => { // 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. +<<<<<<< Updated upstream test("should repeat the string count times", () => { const str = "hello"; const count = -2; // const repeatedStr = repeatStr(str, count); expect(() => repeatStr(str, count)).toThrow("invalid count"); +======= +test("given a string and a negative count, throws an error", () => { + expect(() => repeatStr("hello", -1)).toThrow(); +>>>>>>> Stashed changes }); From e125b64fbf64cefd52e14e0c4783ebe7ba5bad80 Mon Sep 17 00:00:00 2001 From: Liban Jama Date: Fri, 13 Mar 2026 10:34:07 +0000 Subject: [PATCH 5/5] updated --- Sprint-3/2-practice-tdd/count.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 3bec82b90d..f9e440fb77 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -10,21 +10,21 @@ const countChar = require("./count"); // When the function is called with these inputs, // Then it should correctly count occurrences of `char`. -test("should count multiple occurrences of a character", () => { +test("should count all occurrences of a character when it appears multiple times", () => { const str = "aaaaa"; const char = "a"; const count = countChar(str, char); expect(count).toEqual(5); }); -test("should count multiple occurrences of a character", () => { +test("should return 1 when the character appears only once in the string", () => { const str = "house"; const char = "e"; const count = countChar(str, char); expect(count).toEqual(1); }); -test("should count multiple occurrences of a character", () => { +test("should correctly count occurrences of a character appearing twice", () => { const str = "playful"; const char = "l"; const count = countChar(str, char);