From f0c93d57fc1356cadd19fd2d264190f878d67b03 Mon Sep 17 00:00:00 2001 From: Konvaly Date: Tue, 11 Nov 2025 15:47:21 +0000 Subject: [PATCH 1/7] Solved task Sprint-3/2-practice-tdd/count.js and test cases --- Sprint-3/2-practice-tdd/count.js | 6 +++++- Sprint-3/2-practice-tdd/count.test.js | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..a3e58850b 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,9 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + const arrToStr = stringOfCharacters.split(""); + + const countCharInArr = arrToStr.filter((char) => char === findCharacter); + + return countCharInArr.length; } module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 42baf4b4b..1395dc867 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,3 +22,9 @@ test("should count multiple occurrences of a character", () => { // And a character char that does not exist within the case-sensitive str, // When the function is called with these inputs, // Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str. +test("should return 0 if there's no occurrences of the char were found in the case-sensitive str", () => { + const str = "aaaaABcGRja"; + const char = "b"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); From 681f5f5eb984db057e8d094927dff72509452078 Mon Sep 17 00:00:00 2001 From: Konvaly Date: Tue, 11 Nov 2025 22:17:08 +0000 Subject: [PATCH 2/7] Found solution for the first test in Sprint-3/2-practice-tdd/repeat.test.js --- Sprint-3/2-practice-tdd/repeat.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index 00e60d7f3..10778f58e 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -1,5 +1,12 @@ -function repeat() { - return "hellohellohello"; +function repeat(str, count) { + let repeatedStrCountTimes = ""; + + let i = 0; + while (i < count) { + repeatedStrCountTimes += str; + i++; + } + return repeatedStrCountTimes; } module.exports = repeat; From 0b903310d9a389df59b57994c51c694c03e1b558 Mon Sep 17 00:00:00 2001 From: Konvaly Date: Tue, 11 Nov 2025 22:28:06 +0000 Subject: [PATCH 3/7] Found solution for the 2 and 3 test in Sprint-3/2-practice-tdd/repeat.test.js --- Sprint-3/2-practice-tdd/repeat.js | 5 +++++ Sprint-3/2-practice-tdd/repeat.test.js | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index 10778f58e..e1c9a367b 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -1,4 +1,8 @@ function repeat(str, count) { + if (count === 0) { + return ""; + } + let repeatedStrCountTimes = ""; let i = 0; @@ -6,6 +10,7 @@ function repeat(str, count) { repeatedStrCountTimes += str; i++; } + console.log(repeatedStrCountTimes); return repeatedStrCountTimes; } diff --git a/Sprint-3/2-practice-tdd/repeat.test.js b/Sprint-3/2-practice-tdd/repeat.test.js index 34097b09c..c4e088d28 100644 --- a/Sprint-3/2-practice-tdd/repeat.test.js +++ b/Sprint-3/2-practice-tdd/repeat.test.js @@ -20,11 +20,23 @@ test("should repeat the string count times", () => { // Given a target string str and a count equal to 1, // When the repeat function is called with these inputs, // Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition. +test("should return the original string without repetition if count equal to 1", () => { + const str = "Alone"; + const count = 1; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("Alone"); +}); // case: Handle Count of 0: // Given a target string str and a count equal to 0, // When the repeat function is called with these inputs, // Then it should return an empty string, ensuring that a count of 0 results in an empty output. +test("should return an empty string if count equal to 0", () => { + const str = "nonsense"; + const count = 0; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual(""); +}); // case: Negative Count: // Given a target string str and a negative integer count, From e088739018e7bb76027e3c88039d484a2a169276 Mon Sep 17 00:00:00 2001 From: Konvaly Date: Tue, 11 Nov 2025 22:33:57 +0000 Subject: [PATCH 4/7] Found solution for the 4th test in Sprint-3/2-practice-tdd/repeat.test.js --- Sprint-3/2-practice-tdd/repeat.js | 5 ++++- Sprint-3/2-practice-tdd/repeat.test.js | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index e1c9a367b..215fe5ff0 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -2,6 +2,9 @@ function repeat(str, count) { if (count === 0) { return ""; } + if (count < 0) { + return "Error! Negative counts are not valid!"; + } let repeatedStrCountTimes = ""; @@ -10,7 +13,7 @@ function repeat(str, count) { repeatedStrCountTimes += str; i++; } - console.log(repeatedStrCountTimes); + return repeatedStrCountTimes; } diff --git a/Sprint-3/2-practice-tdd/repeat.test.js b/Sprint-3/2-practice-tdd/repeat.test.js index c4e088d28..c2fb3f6b2 100644 --- a/Sprint-3/2-practice-tdd/repeat.test.js +++ b/Sprint-3/2-practice-tdd/repeat.test.js @@ -42,3 +42,9 @@ test("should return an empty string if count equal to 0", () => { // Given a target string str and a negative integer count, // When the repeat function is called with these inputs, // Then it should throw an error or return an appropriate error message, as negative counts are not valid. +test("should return an appropriate error message if count equal to a negative integer", () => { + const str = "negative"; + const count = -5; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("Error! Negative counts are not valid!"); +}); From b516a6163b6ec940e092e231363cc4bf4872e5b7 Mon Sep 17 00:00:00 2001 From: Konvaly Date: Thu, 20 Nov 2025 13:22:53 +0000 Subject: [PATCH 5/7] Added 4 cases and solutions for them to get-ordinal-number --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 11 ++++++++- .../2-practice-tdd/get-ordinal-number.test.js | 24 +++++++++++++++++++ 2 files changed, 34 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 f95d71db1..5b3099dda 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,14 @@ function getOrdinalNumber(num) { - return "1st"; + if (num === 1) { + return "1st"; + } + if (num === 2) { + return "2nd"; + } + if (num === 3) { + return "3rd"; + } + 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 dfe4b6091..b3199d347 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -11,3 +11,27 @@ const getOrdinalNumber = require("./get-ordinal-number"); test("should return '1st' for 1", () => { expect(getOrdinalNumber(1)).toEqual("1st"); }); + +// Case 2: Identify the ordinal number for 2 +// When the number is 2, +// Then the function should return "2nd" + +test("should return '2nd' for 2", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); +}); + +// Case 3: Identify the ordinal number for 3 +// When the number is 3, +// Then the function should return "3rd" + +test("should return '3rd' for 3", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); +}); + +// Case 4: Identify the ordinal number for other numbers +// When the number is 11, +// Then the function should return "11th" + +test("should return '11th' for 11", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); +}); From afc85d728aaa96344ee69cd0437ba8691cabb035 Mon Sep 17 00:00:00 2001 From: Konvaly Date: Thu, 20 Nov 2025 15:01:46 +0000 Subject: [PATCH 6/7] Added 5-th case and solution for them to get-ordinal-number --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 18 +++++++++------- .../2-practice-tdd/get-ordinal-number.test.js | 21 ++++++++++++++----- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index 5b3099dda..b75acdde5 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,13 +1,15 @@ function getOrdinalNumber(num) { - if (num === 1) { - return "1st"; - } - if (num === 2) { - return "2nd"; - } - if (num === 3) { - return "3rd"; + 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"; } 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 b3199d347..ce7970ca9 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -29,9 +29,20 @@ test("should return '3rd' for 3", () => { }); // Case 4: Identify the ordinal number for other numbers -// When the number is 11, -// Then the function should return "11th" - -test("should return '11th' for 11", () => { - expect(getOrdinalNumber(11)).toEqual("11th"); +// If the last digit of number is not 1, 2, 3 +// and the last two digits are not between 11 and 13 +// Then the function should return the number with "th" suffix + +test("should return '44th' for 44", () => { + expect(getOrdinalNumber(44)).toEqual("44th"); + expect(getOrdinalNumber(9)).toEqual("9th"); + expect(getOrdinalNumber(20)).toEqual("20th"); + expect(getOrdinalNumber(100)).toEqual("100th"); + expect(getOrdinalNumber(111)).toEqual("111th"); + expect(getOrdinalNumber(112)).toEqual("112th"); + expect(getOrdinalNumber(113)).toEqual("113th"); + expect(getOrdinalNumber(131)).toEqual("131st"); + expect(getOrdinalNumber(222)).toEqual("222nd"); + expect(getOrdinalNumber(323)).toEqual("323rd"); + expect(getOrdinalNumber(4046486655)).toEqual("4046486655th"); }); From 938dbcf452a339df2479d4b63be8258fa3465080 Mon Sep 17 00:00:00 2001 From: Konvaly Date: Thu, 20 Nov 2025 15:15:27 +0000 Subject: [PATCH 7/7] Added 5-th case, explanation and solution for them to get-ordinal-number --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 3 ++- 1 file changed, 2 insertions(+), 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 ce7970ca9..8b47d408c 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -32,8 +32,9 @@ test("should return '3rd' for 3", () => { // If the last digit of number is not 1, 2, 3 // and the last two digits are not between 11 and 13 // Then the function should return the number with "th" suffix +// otherwise, return the number with the appropriate suffix -test("should return '44th' for 44", () => { +test("should return '44th' for 44; '131st' for 131 etc.", () => { expect(getOrdinalNumber(44)).toEqual("44th"); expect(getOrdinalNumber(9)).toEqual("9th"); expect(getOrdinalNumber(20)).toEqual("20th");