From de7f533c004a6a9f9850db0747274ff220b1ab69 Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Sat, 4 Jul 2026 21:32:30 +0100 Subject: [PATCH 1/9] Add a test for countChar --- Sprint-3/2-practice-tdd/count.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf..d6b063b7f 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,3 +22,10 @@ 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 not find any occurrences", () => { + const str = "aaaaaaaa"; + const char = "something"; + + const count = countChar(str, char); + expect(count).toEqual(0); +}); From dda4bf73191b1c76daa8036728dc74af94766e4b Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Sat, 4 Jul 2026 21:33:24 +0100 Subject: [PATCH 2/9] Change the input of a test to be smaller --- Sprint-3/2-practice-tdd/count.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index d6b063b7f..18135fafe 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -24,7 +24,7 @@ test("should count multiple occurrences of a character", () => { // Then it should return 0, indicating that no occurrences of `char` were found. test("should not find any occurrences", () => { const str = "aaaaaaaa"; - const char = "something"; + const char = "b"; const count = countChar(str, char); expect(count).toEqual(0); From 274894ed2e42fa91d0e6adff215235e66fe4ef19 Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Sat, 11 Jul 2026 15:41:21 +0100 Subject: [PATCH 3/9] Write tests for repeat-str.js --- 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 a3fc1196c..3cd29b9ef 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -21,12 +21,32 @@ test("should repeat the string count times", () => { // When the repeatStr function is called with these inputs, // Then it should return the original `str` without repetition. +test("Should return the original string with no repetitions", () => { + const str = "hello"; + const count = 1; + const repeatedStr = repeatedStr(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", () => { + const str = "hello"; + const count = 0; + const repeatedStr = repeatedStr(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, as negative counts are not valid", () => { + const str = "hello"; + const count = -1; + const repeatedStr = repeatedStr(str, count); + expect(repeatedStr).toThrow(Error); +}); From 12ce8632bf48155bdf9605f2d380a5f79f3fe80a Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Sat, 11 Jul 2026 15:41:47 +0100 Subject: [PATCH 4/9] Write tests for get-ordinal-number.js --- .../2-practice-tdd/get-ordinal-number.test.js | 51 +++++++++++++++++++ 1 file changed, 51 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 adfa58560..bfc68aed0 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,54 @@ 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"); + expect(getOrdinalNumber(133)).toEqual("133rd"); +}); +test("should append 'th' for numbers ending with 0, 4-9, 11, 12, 13", () => { + // 0 + expect(getOrdinalNumber(0)).toEqual("0th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(100)).toEqual("100th"); + // 4 + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(24)).toEqual("24th"); + expect(getOrdinalNumber(134)).toEqual("134th"); + + // 5 + expect(getOrdinalNumber(5)).toEqual("5th"); + expect(getOrdinalNumber(25)).toEqual("25th"); + expect(getOrdinalNumber(135)).toEqual("135th"); + + // 6 + expect(getOrdinalNumber(6)).toEqual("6th"); + expect(getOrdinalNumber(26)).toEqual("26th"); + expect(getOrdinalNumber(136)).toEqual("136th"); + + // 7 + expect(getOrdinalNumber(7)).toEqual("7th"); + expect(getOrdinalNumber(27)).toEqual("27th"); + expect(getOrdinalNumber(137)).toEqual("137th"); + + // 8 + expect(getOrdinalNumber(8)).toEqual("8th"); + expect(getOrdinalNumber(28)).toEqual("28th"); + expect(getOrdinalNumber(138)).toEqual("138th"); + + // 9 + expect(getOrdinalNumber(9)).toEqual("9th"); + expect(getOrdinalNumber(29)).toEqual("29th"); + expect(getOrdinalNumber(139)).toEqual("139th"); +}); + +// edge cases +test("should throw an error when given a wrong input type", () => { + expect(getOrdinalNumber("string")).toThrow(Error); +}); From 1a1df6fe322f5c72234548ced480d1b17cdd7040 Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Sat, 11 Jul 2026 15:47:53 +0100 Subject: [PATCH 5/9] Implement countChar in count.js --- Sprint-3/2-practice-tdd/count.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..2604d29f3 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 + let count = 0; + + for (const i of stringOfCharacters) { + if (i === findCharacter) { + count++; + } + } + + return count; } module.exports = countChar; From db30440d1708152b9bca6b874338f4ed41d9767c Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Sat, 11 Jul 2026 16:01:58 +0100 Subject: [PATCH 6/9] Fix tests for repeat-str.js --- Sprint-3/2-practice-tdd/repeat-str.test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index 3cd29b9ef..b2f055e73 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -24,7 +24,7 @@ test("should repeat the string count times", () => { test("Should return the original string with no repetitions", () => { const str = "hello"; const count = 1; - const repeatedStr = repeatedStr(str, count); + const repeatedStr = repeatStr(str, count); expect(repeatedStr).toEqual("hello"); }); @@ -35,7 +35,7 @@ test("Should return the original string with no repetitions", () => { test("Should return an empty string", () => { const str = "hello"; const count = 0; - const repeatedStr = repeatedStr(str, count); + const repeatedStr = repeatStr(str, count); expect(repeatedStr).toEqual(""); }); @@ -47,6 +47,5 @@ test("Should return an empty string", () => { test("Should throw an error, as negative counts are not valid", () => { const str = "hello"; const count = -1; - const repeatedStr = repeatedStr(str, count); - expect(repeatedStr).toThrow(Error); + expect(() => repeatStr(str, count)).toThrow("Expected a positive integer"); }); From 73f8459e58b751db50296aebd47ae9bae245fc4e Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Sat, 11 Jul 2026 16:02:20 +0100 Subject: [PATCH 7/9] Implement repeat-str --- Sprint-3/2-practice-tdd/repeat-str.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 2af0a2cea..176f35f62 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) { // 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"; + if (count < 0) { + throw new Error("Expected a positive integer"); + } + + let out = ""; + + for (let i = 0; i < count; i++) { + out = out + str; + } + + return out; } module.exports = repeatStr; From 1a4ec4ec6335e406064a3c8986d2f2c213b2670f Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Sat, 18 Jul 2026 15:55:49 +0100 Subject: [PATCH 8/9] Add more tests to cover 10,11,12,13 --- .../2-practice-tdd/get-ordinal-number.test.js | 16 ++++++++++++++-- 1 file changed, 14 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 bfc68aed0..66848d8a4 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -29,7 +29,7 @@ test("should append 'rd' for numbers ending with 3, except those ending with 13" expect(getOrdinalNumber(23)).toEqual("23rd"); expect(getOrdinalNumber(133)).toEqual("133rd"); }); -test("should append 'th' for numbers ending with 0, 4-9, 11, 12, 13", () => { +test("should append 'th' for numbers ending with 0, 4-9, 10, 11, 12, 13", () => { // 0 expect(getOrdinalNumber(0)).toEqual("0th"); expect(getOrdinalNumber(10)).toEqual("10th"); @@ -63,9 +63,21 @@ test("should append 'th' for numbers ending with 0, 4-9, 11, 12, 13", () => { expect(getOrdinalNumber(9)).toEqual("9th"); expect(getOrdinalNumber(29)).toEqual("29th"); expect(getOrdinalNumber(139)).toEqual("139th"); + + // 10 + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(100)).toEqual("100th"); + + // 11, 12, 13 + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); }); // edge cases test("should throw an error when given a wrong input type", () => { - expect(getOrdinalNumber("string")).toThrow(Error); + expect(() => getOrdinalNumber("testing string")).toThrow("Invalid type for "); + expect(() => getOrdinalNumber("")).toThrow(); + expect(() => getOrdinalNumber(null)).toThrow(); + expect(() => getOrdinalNumber(undefined)).toThrow(); }); From f1f96b4a858761bc136ea01aa1bcaac5009b2871 Mon Sep 17 00:00:00 2001 From: Vitalii Kmit Date: Sat, 18 Jul 2026 15:56:40 +0100 Subject: [PATCH 9/9] Implement getOrdinalNumber --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 28 ++++++++++++++++++- 1 file changed, 27 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..198b2f03d 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,31 @@ function getOrdinalNumber(num) { - return "1st"; + // handle special cases + + if (typeof num !== "number" || Number.isNaN(num)) { + throw new Error(`Invalid type for ${num}, expected Number`); + } + + const snum = String(num); // num as a string + const thList = ["0", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"]; // list of numbers that should end up with th as a suffix + + const lastCharIndex = snum.length - 1; + const lastOne = snum[lastCharIndex]; + const lastTwo = snum.slice(lastCharIndex - 1); + + if (thList.includes(lastTwo) || thList.includes(lastOne)) { + return snum + "th"; + } + + switch (lastOne) { + case "1": + return snum + "st"; + case "2": + return snum + "nd"; + case "3": + return snum + "rd"; + default: + break; + } } module.exports = getOrdinalNumber;