From 9f01d0889d3d42f7d4d38373c05fe1a00d91deb3 Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Thu, 16 Jul 2026 19:53:59 +0100 Subject: [PATCH 1/6] implemented function countChart --- 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..39f0058613 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 countCharacter = 0; + for (let i = 0; i < stringOfCharacters.length; i++){ + if (stringOfCharacters.charAt(i) === findCharacter){ + countCharacter += 1; + } + } + return countCharacter } + module.exports = countChar; From 8edf045883f0edd7a05e794de63432728f9c702f Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Thu, 16 Jul 2026 19:55:05 +0100 Subject: [PATCH 2/6] added jest cases to ensure the functions is works correctly --- Sprint-3/2-practice-tdd/count.test.js | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf7..969b52b2d3 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,3 +22,31 @@ 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 count multiple occurrences of a character", () => { + const str = "banana"; + const char = "n"; + const count = countChar(str, char); + expect(count).toEqual(2); +}); + +test("should count multiple occurrences of a character", () => { + const str = "appleTree"; + const char = "e"; + const count = countChar(str, char); + expect(count).toEqual(3); +}); + +test("should count multiple occurrences of a character", () => { + const str = "strawberry"; + const char = "r"; + const count = countChar(str, char); + expect(count).toEqual(3); +}); + +test("should count multiple occurrences of a character", () => { + const str = "ghost"; + const char = "o"; + const count = countChar(str, char); + expect(count).toEqual(1); +}); \ No newline at end of file From 09ce3cc6a550f7c6077e8aa679db72c19b904d8a Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Thu, 16 Jul 2026 19:55:35 +0100 Subject: [PATCH 3/6] implemented function --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 15 ++++++++++++++- 1 file changed, 14 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..43e1a8f028 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"; + if ( typeof num !== "number" ){ + throw new Error('Not a number') + } + + if (num % 10 === 1 && num % 100 !== 11) { + return `${num}st`; + } else if (num % 10 === 2 && num % 100 !== 12 ) { + return `${num}nd`; + } else if (num % 10 === 3 && num % 100 !== 13) { + return `${num}rd`; + } else { + + return `${num}th`; + } } module.exports = getOrdinalNumber; From 2d271a1aeb58e63445b249b70cfebb3694206481 Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Thu, 16 Jul 2026 19:56:28 +0100 Subject: [PATCH 4/6] added test jest cases to check the function working as intended --- .../2-practice-tdd/get-ordinal-number.test.js | 33 +++++++++++++++++++ 1 file changed, 33 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..42bfaa35bd 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -17,4 +17,37 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(1)).toEqual("1st"); expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); + expect(getOrdinalNumber(1101)).toEqual("1101st"); +}); + +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"); + expect(getOrdinalNumber(22222)).toEqual("22222nd"); +}); + +test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(133)).toEqual("133rd"); + expect(getOrdinalNumber(33333)).toEqual("33333rd"); +}); + +test("should append 'th' for numbers ending with 11, 12, 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"); + expect(getOrdinalNumber(11111)).toEqual("11111th"); + expect(getOrdinalNumber(11112)).toEqual("11112th"); + expect(getOrdinalNumber(11113)).toEqual("11113th"); +}); + +test("should throw an error message", () => { + expect(() => { + getOrdinalNumber("Hello"); + }).toThrow(); }); From 50bce3537f53cd64b62defddfb8c94a622e4db16 Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Thu, 16 Jul 2026 19:57:01 +0100 Subject: [PATCH 5/6] implemented function --- Sprint-3/2-practice-tdd/repeat-str.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 2af0a2cea7..55b48ee389 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,7 +1,13 @@ -function repeatStr() { - // Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat). - // The goal is to re-implement that function, not to use it. - return "hellohellohello"; +function repeatStr(str, count) { + if (count < 0) { + throw new Error("Error"); + } + + let repeatedString = ""; + for (let i = 0; i < count; i++) { + repeatedString += str; + } + return repeatedString; } module.exports = repeatStr; From a2580222c2ded122be9ae30ab9b9504c90c395cd Mon Sep 17 00:00:00 2001 From: bodoszidi Date: Thu, 16 Jul 2026 19:58:12 +0100 Subject: [PATCH 6/6] added jest test cases to check the function --- Sprint-3/2-practice-tdd/repeat-str.test.js | 20 ++++++++++++++++++++ 1 file changed, 20 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..4b5c3d17c0 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -20,13 +20,33 @@ 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 repeat the string count times", () => { + const str = "what"; + const count = 1; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("what"); +}); // 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", () => { + 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 message", () => { + const str = "hello"; + const count = -3; + expect(() => { + repeatStr(str, count); + }).toThrow(); +});