From 02f9da3d62911a38b60e4497bfbf70afd7e3b24d Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Sat, 1 Aug 2026 15:29:29 +0100 Subject: [PATCH 1/6] Work on sprint 3 1-get-angle-type put in code using "if" function. --- Sprint-3/2-practice-tdd/count.js | 12 ++++++++++-- Sprint-3/2-practice-tdd/count.test.js | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..cd9d2d9348 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,13 @@ +// function countChar(stringOfCharacters, findCharacter) { +// return 5 +// } function countChar(stringOfCharacters, findCharacter) { - return 5 + let countChar = 0; + for (let stringNum = 0; stringNum < stringOfCharacters.length; stringNum++) { + if (findCharacter === stringOfCharacters[stringNum]){ + countChar++ + } + } + return countChar } - 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..b5761020b0 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -17,8 +17,29 @@ test("should count multiple occurrences of a character", () => { expect(count).toEqual(5); }); +test("should count multiple occurrences of a character", () => { + const str = "aaa aa"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(5); +}); + +test("should count multiple occurrences of a character with random characters", () => { + const str = "ajhyabhaakaka"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(6); +}) + // 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("should return 0 with no occurrence of the character", () => { + const str ="abcd"; + const char = "e"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); + From 1ca6ee18d5bfa95bffcb5dec16be8f3a6f9b8074 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Sat, 1 Aug 2026 16:09:35 +0100 Subject: [PATCH 2/6] SPrint 3- practice-tdd - get-ordinal-numbers Making of code and tests --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 11 ++++++++++- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 5 +++++ 2 files changed, 15 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..ad65497f4a 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"; +// } + function getOrdinalNumber(num) { - return "1st"; + let text = num.toString(); + if (text === "11") { + return (text + "th"); + } + return (text + "st"); } +// getOrdinalNumber(1)).toEqual("1st") 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..1cf5ac1d18 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,8 @@ 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 'th' for number 11", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + +}); \ No newline at end of file From 642bcd82aef2b0fff4283837ee5099380d37b38c Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Fri, 14 Aug 2026 12:17:49 +0100 Subject: [PATCH 3/6] Updating count.test..jest --- Sprint-3/2-practice-tdd/count.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index b5761020b0..c7dc1d7b07 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -17,11 +17,11 @@ test("should count multiple occurrences of a character", () => { expect(count).toEqual(5); }); -test("should count multiple occurrences of a character", () => { - const str = "aaa aa"; - const char = "a"; +test("should count multiple occurrences of a character with spaces", () => { + const str = "eee ee e e"; + const char = "e"; const count = countChar(str, char); - expect(count).toEqual(5); + expect(count).toEqual7; }); test("should count multiple occurrences of a character with random characters", () => { From 5b95434440e0e371203a20bd977822027a1a3281 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Fri, 14 Aug 2026 13:18:39 +0100 Subject: [PATCH 4/6] Wokring on repeat-str.js and repeat-str.test.js --- Sprint-3/2-practice-tdd/repeat-str.js | 16 +++++++++++++--- Sprint-3/2-practice-tdd/repeat-str.test.js | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 2af0a2cea7..8133246fd8 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,7 +1,17 @@ -function repeatStr() { +function repeatStr(str, count) { + let result = ""; + if (count < 0) { + throw new Error("cannot be negative number") + } + + for (let i=0; i < count; i++) { + result = result + str + } // 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"; -} + return result; + +}; 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..d6b838628e 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 return the string as the str for counting 1 time", () => { + 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 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 error when count is negative", ()=> { + const str="hello"; + const count =-6; + expect(() => repeatStr(str, count)).toThrow("cannot be negative number"); + +}); From e1a210bac3130420006f249f8b5b650ed1d9309e Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Fri, 14 Aug 2026 13:29:20 +0100 Subject: [PATCH 5/6] fixes for count --- Sprint-3/2-practice-tdd/count.js | 4 ++-- Sprint-3/2-practice-tdd/count.test.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index cd9d2d9348..7468f4e1f4 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -5,9 +5,9 @@ function countChar(stringOfCharacters, findCharacter) { let countChar = 0; for (let stringNum = 0; stringNum < stringOfCharacters.length; stringNum++) { if (findCharacter === stringOfCharacters[stringNum]){ - countChar++ + countChar++; } } - return countChar + return countChar; } module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index c7dc1d7b07..75f4cc5054 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -25,7 +25,7 @@ test("should count multiple occurrences of a character with spaces", () => { }); test("should count multiple occurrences of a character with random characters", () => { - const str = "ajhyabhaakaka"; + const str = "ajhyabhaa kaak"; const char = "a"; const count = countChar(str, char); expect(count).toEqual(6); From 0a272b6074481b03ef33c654a89a766d4a7053dd Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Sat, 15 Aug 2026 12:29:36 +0100 Subject: [PATCH 6/6] Adding extra numbers for get-orginal-number for both testing and main code. --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 18 +++++++++---- .../2-practice-tdd/get-ordinal-number.test.js | 26 ++++++++++++++++++- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index ad65497f4a..2de7f70695 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -3,11 +3,19 @@ // } function getOrdinalNumber(num) { - let text = num.toString(); - if (text === "11") { - return (text + "th"); - } - return (text + "st"); + let text = num.toString(); + + if (Math.abs(num) >= 11 && Math.abs(num) <=13) { + return (text + "th") + } else if (text.slice(-1) === "1") { + return (text + "st") + } else if (text.slice(-1) === "2") { + return (text + "nd") + } else if (text.slice(-1) === "3") { + return (text +"rd") + }; + + return (text + "th"); } // getOrdinalNumber(1)).toEqual("1st") 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 1cf5ac1d18..8e8b8a4e6b 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -19,7 +19,31 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(131)).toEqual("131st"); }); -test("should append 'th' for number 11", () => { +// Case 2: Numbers ending with 2 should return with "nd" to the number +// Unless number 12 should return with the "th" to the number +test("should append 'nd' for numbers ending in 2", () => { + expect(getOrdinalNumber(22)).toEqual("22nd"); +}); + +// Case 3: Numbers ending with 3 should return with a "rd" to the number +// Unless number is 13 then it should return with the "th" to the number +test("should append 'rd' for numbers ending with 3", () => { + expect(getOrdinalNumber(23)).toEqual("23rd"); +}); + + + +// Case 4: all other numbers should return with a "th" to the number + +test("should append 'th' for all other numbers", () => { expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); + expect(getOrdinalNumber(194)).toEqual("194th"); +}); +// Case 5: Negative numbers follow same rules. +test("should follow rules as previous tests while still showing '-' value", () => { + expect(getOrdinalNumber(-12)).toEqual("-12th"); + expect(getOrdinalNumber(-52)).toEqual("-52nd"); }); \ No newline at end of file