From d83cfa4b93c61f078325268f2919d02b9cf6e16f Mon Sep 17 00:00:00 2001 From: Maryanne Mosonik Date: Wed, 25 Feb 2026 03:31:59 +0300 Subject: [PATCH 01/10] Implemented repeatStr function --- Sprint-3/2-practice-tdd/repeat-str.js | 7 +++++-- 1 file changed, 5 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..21c746c6a7 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("Count must be a non-negative"); + } + return str.repeat(count); } module.exports = repeatStr; From b39a0333cf65ecb99572b051991876078f25e2e9 Mon Sep 17 00:00:00 2001 From: Maryanne Mosonik Date: Wed, 25 Feb 2026 03:28:10 +0300 Subject: [PATCH 02/10] Added tests for repeatStr function to handle edge cases --- Sprint-3/2-practice-tdd/repeat-str.test.js | 17 +++++++++++++++++ 1 file changed, 17 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..e6e5c81dfe 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -20,13 +20,30 @@ 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 return the original string when count is 1", () => { + 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 return an empty string when count is 0", () => { + 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 throw an error when count is negative", () => { + const str = "hello"; + const count = -1; + expect(() => repeatStr(str, count)).toThrow("Count must be a non-negative integer"); +}); From 86d8ca93ecab93ff27e1b22bd445042dc7e8449e Mon Sep 17 00:00:00 2001 From: Maryanne Mosonik Date: Wed, 25 Feb 2026 03:17:06 +0300 Subject: [PATCH 03/10] Refactor getOrdinalNumber function to correctly return ordinal suffixes based on input number --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 20 ++++++++++++++++++- 1 file changed, 19 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..a94b799d08 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,23 @@ function getOrdinalNumber(num) { - return "1st"; + const str = String(num); + + const lastTwo = num % 100; + + if (lastTwo === 11 || lastTwo === 12 || lastTwo === 13) { + return str + "th"; + } + const lastDigit = num % 10; +if (lastDigit === 1) { + return str + "st"; + } else if (lastDigit === 2) { + return str + "nd"; + } else if (lastDigit === 3) { + return str + "rd"; + } else { + return str + "th"; + } + + } module.exports = getOrdinalNumber; From 3175f1342c362e7d7a810fca1b5ba6d3d14fdeaa Mon Sep 17 00:00:00 2001 From: Maryanne Mosonik Date: Wed, 25 Feb 2026 03:08:53 +0300 Subject: [PATCH 04/10] Added tests for ordinal number suffixes in getOrdinalNumber function --- .../2-practice-tdd/get-ordinal-number.test.js | 17 +++++++++++++++++ 1 file changed, 17 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..62279e0b76 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,20 @@ 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, except those ending with 12", () => { + 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(23)).toEqual("23rd"); +}); +test("should append 'th' for numbers ending with 11, 12, or 13", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); +}); +test("should append 'th' for other numbers", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(10)).toEqual("10th"); +}); From bef7de6b333e40206445a42804d94dde4b41f52d Mon Sep 17 00:00:00 2001 From: Maryanne Mosonik Date: Wed, 25 Feb 2026 03:03:30 +0300 Subject: [PATCH 05/10] Implement countChar function and add tests for character occurrences --- Sprint-3/2-practice-tdd/count.js | 10 ++++++++-- Sprint-3/2-practice-tdd/count.test.js | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..5f66ee96f9 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,11 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 -} + let count = 0; + for(let char of stringOfCharacters){ + if (char === findCharacter) { + count++; + } + } + return count; +} 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..2dc57106c3 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -16,6 +16,12 @@ test("should count multiple occurrences of a character", () => { const count = countChar(str, char); expect(count).toEqual(5); }); +test ("should return 0 when the character does not exist in the string", () => { + const str = "exist"; + const char = "z"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); // Scenario: No Occurrences // Given the input string `str`, From 8757e5a9880f6d7f0fb0ea805de114f86784c6b9 Mon Sep 17 00:00:00 2001 From: Maryanne Mosonik Date: Fri, 6 Mar 2026 23:55:32 +0300 Subject: [PATCH 06/10] Tested more scenarios --- Sprint-3/2-practice-tdd/count.test.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 2dc57106c3..20eb9c44ef 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,6 +22,29 @@ test ("should return 0 when the character does not exist in the string", () => { const count = countChar(str, char); expect(count).toEqual(0); }); +test("should return 0 when the input string is empty", () => { + const str = ""; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); +test("should return 0 when the input character is an empty string", () => { + const str = "test"; + const char = ""; + const count = countChar(str, char); + expect(count).toEqual(0); +}); +test("should return 0 when both the input string and character are empty", () => { + const str = ""; + const char = ""; + const count = countChar(str, char); + expect(count).toEqual(0); +}); +// Scenario: Empty String +// Given an empty input string `str`, +// And any character `char` (e.g., 'a'), +// When the function is called with these inputs, +// Then it should return 0, indicating that no occurrences of `char` were found in the empty string. // Scenario: No Occurrences // Given the input string `str`, From 3bb795faf0684263a520458bf5e0d0b26ece88e3 Mon Sep 17 00:00:00 2001 From: Maryanne Mosonik Date: Sat, 7 Mar 2026 00:03:33 +0300 Subject: [PATCH 07/10] Tests for non-alphabet characters and is case-sensitive --- Sprint-3/2-practice-tdd/count.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 20eb9c44ef..0888ee28e9 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -40,6 +40,18 @@ test("should return 0 when both the input string and character are empty", () => const count = countChar(str, char); expect(count).toEqual(0); }); +test("should be case sensitive when counting characters", () => { + const str = "AaAaA"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(2); +}); +test("should count non-alphabet characters", () => { + const str = "12345!"; + const char = "1"; + const count = countChar(str, char); + expect(count).toEqual(1); +}); // Scenario: Empty String // Given an empty input string `str`, // And any character `char` (e.g., 'a'), From cc879bbb791138b7b50ec87526a99635f2820036 Mon Sep 17 00:00:00 2001 From: Maryanne Mosonik Date: Sat, 7 Mar 2026 00:20:41 +0300 Subject: [PATCH 08/10] Ran Prettier and formatted the entire file --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 6 ++---- 1 file changed, 2 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 a94b799d08..fc378726e6 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -6,8 +6,8 @@ function getOrdinalNumber(num) { if (lastTwo === 11 || lastTwo === 12 || lastTwo === 13) { return str + "th"; } - const lastDigit = num % 10; -if (lastDigit === 1) { + const lastDigit = num % 10; + if (lastDigit === 1) { return str + "st"; } else if (lastDigit === 2) { return str + "nd"; @@ -16,8 +16,6 @@ if (lastDigit === 1) { } else { return str + "th"; } - - } module.exports = getOrdinalNumber; From 6a8425e8876f4fd1c94ad38d25945c63229750bd Mon Sep 17 00:00:00 2001 From: Maryanne Mosonik Date: Sat, 7 Mar 2026 00:33:16 +0300 Subject: [PATCH 09/10] Added more descriptive test cases. --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 8 ++++++-- 1 file changed, 6 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 62279e0b76..d175e36698 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -30,8 +30,12 @@ test("should append 'rd' for numbers ending with 3, except those ending with 13" 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"); + expect(getOrdinalNumber(111)).toEqual("111th"); + expect(getOrdinalNumber(112)).toEqual("112th"); + expect(getOrdinalNumber(113)).toEqual("113th"); }); -test("should append 'th' for other numbers", () => { +test("should append 'th' for numbers not ending with 1, 2, or 3", () => { expect(getOrdinalNumber(4)).toEqual("4th"); expect(getOrdinalNumber(10)).toEqual("10th"); -}); +}); From f047e5961920589386749916936fcb59aec496ec Mon Sep 17 00:00:00 2001 From: Maryanne Mosonik Date: Sat, 7 Mar 2026 02:06:33 +0300 Subject: [PATCH 10/10] Added the word integer --- Sprint-3/2-practice-tdd/repeat-str.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 21c746c6a7..a3f1096647 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,6 +1,6 @@ -function repeatStr(str,count) { +function repeatStr(str, count) { if (count < 0) { - throw new Error("Count must be a non-negative"); + throw new Error("Count must be a non-negative integer"); } return str.repeat(count); }