From 639af4c4451605f9638b035f03014c23f0a2bb76 Mon Sep 17 00:00:00 2001 From: RomanSanaye Date: Wed, 4 Mar 2026 17:28:49 +0000 Subject: [PATCH 1/4] Implement functions to repeat strings, get ordinal numbers, and count; pass all test cases --- Sprint-3/2-practice-tdd/count.js | 15 +++++++++++- Sprint-3/2-practice-tdd/count.test.js | 6 +++++ Sprint-3/2-practice-tdd/get-ordinal-number.js | 16 ++++++++++++- .../2-practice-tdd/get-ordinal-number.test.js | 24 +++++++++++++++++++ Sprint-3/2-practice-tdd/repeat-str.js | 7 ++++-- Sprint-3/2-practice-tdd/repeat-str.test.js | 16 ++++++++----- 6 files changed, 74 insertions(+), 10 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..523753cc09 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,18 @@ +// our function; function countChar(stringOfCharacters, findCharacter) { - return 5 + if (!stringOfCharacters || !findCharacter) { + return 0; + } + let numberOfChar = 0; + for (let wantedChar of stringOfCharacters) { + if (wantedChar === findCharacter) { + numberOfChar++; + } + if (numberOfChar === 0) { + return `0 ${findCharacter} found.` + } + } + return numberOfChar; } 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..6bbef9e31f 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 `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 if there is not a character occurrence", () => { + const str = "aaaaa"; + const char = "b"; + const count = countChar(str, char); + expect(count).toEqual(`0 ${char} found.`); +}); \ No newline at end of file diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..19bebff239 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,19 @@ +// lets develop our function. function getOrdinalNumber(num) { - return "1st"; + + const lastDigit = num % 10; // ==> 111 % 10 = 11.1 last digit is 1. + const lastTwoDigits = num % 100; // 111 % 100 = 111 last two digits 11. + + if (lastTwoDigits >= 11 && lastTwoDigits <= 13){ + return `${num}th`;// ==> finds the last two digits to equal (11,12,13) + } + if(lastDigit == 1){ + return `${num}st`; + }else if (lastDigit == 2){ + return `${num}nd`; + }else 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..7e6adfe3d9 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,27 @@ 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(222)).toEqual("222nd"); +}); +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(333)).toEqual("333rd"); +}); +test("should append 'th' for numbers ending with 4 and more than 4", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(44)).toEqual("44th"); + expect(getOrdinalNumber(444)).toEqual("444th"); + expect(getOrdinalNumber(5)).toEqual("5th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(100)).toEqual("100th"); + expect(getOrdinalNumber(105)).toEqual("105th"); +}); +test("should append 'th' for numbers ending with 11, 12 and 13", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); +}); \ No newline at end of file diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b003..19483e0b3a 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("Negative counts are not valid"); + if (count === 0) return ""; + else return str.repeat(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..e5efb88d30 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -10,23 +10,27 @@ const repeatStr = require("./repeat-str"); // Then it should return a string that contains the original `str` repeated `count` times. test("should repeat the string count times", () => { - const str = "hello"; - const count = 3; - const repeatedStr = repeatStr(str, count); - expect(repeatedStr).toEqual("hellohellohello"); + expect(repeatStr("Love", 3)).toEqual("LoveLoveLove"); }); // Case: handle count of 1: // 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 print the original string", () => { + expect(repeatStr("Love", 1)).toEqual("Love"); +}); // 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", () => { + expect(repeatStr("Love", 0)).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 and error when count is a negative number", () => { + expect(()=> repeatStr("Love", -3)).toThrow("Negative counts are not valid"); +}); \ No newline at end of file From e73df46ce8ad26853f80623761fd042ca24cc4f2 Mon Sep 17 00:00:00 2001 From: RomanSanaye Date: Mon, 9 Mar 2026 18:08:14 +0000 Subject: [PATCH 2/4] WIP: updates to repeat-str.test.js --- Sprint-3/2-practice-tdd/repeat-str.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index e5efb88d30..3272d6f601 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -32,5 +32,5 @@ test("should return an empty string", () => { // When the repeatStr function is called with these inputs, // Then it should throw an error, as negative counts are not valid. test("should throw and error when count is a negative number", () => { - expect(()=> repeatStr("Love", -3)).toThrow("Negative counts are not valid"); + expect(() => repeatStr("Love", -3)).toThrow("Negative counts are not valid"); }); \ No newline at end of file From da793bdc6daf6f6bd8b90d2165b979e086eeb5d8 Mon Sep 17 00:00:00 2001 From: RomanSanaye Date: Thu, 19 Mar 2026 13:09:51 +0000 Subject: [PATCH 3/4] practice-tdd files were updated --- Sprint-3/2-practice-tdd/count.js | 2 +- Sprint-3/2-practice-tdd/count.test.js | 4 ++-- Sprint-3/2-practice-tdd/get-ordinal-number.js | 13 ++++++------- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 13 +++++++------ Sprint-3/2-practice-tdd/repeat-str.test.js | 6 +++--- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 523753cc09..6636293d38 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -9,7 +9,7 @@ function countChar(stringOfCharacters, findCharacter) { numberOfChar++; } if (numberOfChar === 0) { - return `0 ${findCharacter} found.` + return 0; } } return numberOfChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 6bbef9e31f..a990a2db94 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -26,5 +26,5 @@ test("should return 0 if there is not a character occurrence", () => { const str = "aaaaa"; const char = "b"; const count = countChar(str, char); - expect(count).toEqual(`0 ${char} found.`); -}); \ No newline at end of file + expect(count).toEqual(0); +}); diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index 19bebff239..503ed0d1d0 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,17 +1,16 @@ // lets develop our function. function getOrdinalNumber(num) { - const lastDigit = num % 10; // ==> 111 % 10 = 11.1 last digit is 1. const lastTwoDigits = num % 100; // 111 % 100 = 111 last two digits 11. - - if (lastTwoDigits >= 11 && lastTwoDigits <= 13){ - return `${num}th`;// ==> finds the last two digits to equal (11,12,13) + + if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { + return `${num}th`; // ==> finds the last two digits to equal (11,12,13) } - if(lastDigit == 1){ + if (lastDigit == 1) { return `${num}st`; - }else if (lastDigit == 2){ + } else if (lastDigit == 2) { return `${num}nd`; - }else if (lastDigit == 3){ + } else if (lastDigit == 3) { return `${num}rd`; } else 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 7e6adfe3d9..f7f66ff80c 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -28,17 +28,18 @@ test("should append 'rd' for numbers ending with 3, except those ending with 13" expect(getOrdinalNumber(33)).toEqual("33rd"); expect(getOrdinalNumber(333)).toEqual("333rd"); }); -test("should append 'th' for numbers ending with 4 and more than 4", () => { +test("should append 'th' for numbers ending with 4-9 or 0 (except 11-13)", () => { expect(getOrdinalNumber(4)).toEqual("4th"); - expect(getOrdinalNumber(44)).toEqual("44th"); - expect(getOrdinalNumber(444)).toEqual("444th"); expect(getOrdinalNumber(5)).toEqual("5th"); + expect(getOrdinalNumber(6)).toEqual("6th"); + expect(getOrdinalNumber(7)).toEqual("7th"); + expect(getOrdinalNumber(8)).toEqual("8th"); + expect(getOrdinalNumber(9)).toEqual("9th"); expect(getOrdinalNumber(10)).toEqual("10th"); - expect(getOrdinalNumber(100)).toEqual("100th"); - expect(getOrdinalNumber(105)).toEqual("105th"); + expect(getOrdinalNumber(14)).toEqual("14th"); }); test("should append 'th' for numbers ending with 11, 12 and 13", () => { expect(getOrdinalNumber(11)).toEqual("11th"); expect(getOrdinalNumber(12)).toEqual("12th"); expect(getOrdinalNumber(13)).toEqual("13th"); -}); \ No newline at end of file +}); diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index 3272d6f601..f8e9c61dae 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -17,14 +17,14 @@ 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 print the original string", () => { +test("should return the original string when count is 1", () => { expect(repeatStr("Love", 1)).toEqual("Love"); }); // 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", () => { +test("should return an empty string when count is 0", () => { expect(repeatStr("Love", 0)).toEqual(""); }); // Case: Handle negative count: @@ -33,4 +33,4 @@ test("should return an empty string", () => { // Then it should throw an error, as negative counts are not valid. test("should throw and error when count is a negative number", () => { expect(() => repeatStr("Love", -3)).toThrow("Negative counts are not valid"); -}); \ No newline at end of file +}); From 48f34dddbfba6a4a528919a8bd5eed458ec48c81 Mon Sep 17 00:00:00 2001 From: RomanSanaye Date: Thu, 19 Mar 2026 15:40:54 +0000 Subject: [PATCH 4/4] bug fixed from count.js --- 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 6636293d38..8571dfea7b 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -8,9 +8,6 @@ function countChar(stringOfCharacters, findCharacter) { if (wantedChar === findCharacter) { numberOfChar++; } - if (numberOfChar === 0) { - return 0; - } } return numberOfChar; }