From 0dc502dea8bb880678c21ef116315c9df729287a Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Fri, 10 Jul 2026 17:30:40 +0100 Subject: [PATCH 1/4] count function --- 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 95b6ebb7d4..79977793e5 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 (let i = 0; i < stringOfCharacters.length; i++) { + if (stringOfCharacters[i] === findCharacter) { + count++; + } + } + + return count; } module.exports = countChar; From 9733fa31dce61e8c80a8cba4db9a6cf5f2ef01aa Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Fri, 10 Jul 2026 17:47:32 +0100 Subject: [PATCH 2/4] count.test answer --- Sprint-3/2-practice-tdd/count.test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf7..3400c0f729 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,3 +22,13 @@ 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. + +// to solve this issue, we will implement a test case that checks for the scenario where the character is not found in the string. +// The test will call the countChar function with a string and a character that does not exist in that string, and it will assert that the returned count is 0. +// here is the code for the test case: +test("should return 0 when character is not found", () => { + const str = "hello"; + const char = "x"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); From 7991a9b5ae9245f010d3772b4259ba5e6490f8bd Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Fri, 10 Jul 2026 17:59:47 +0100 Subject: [PATCH 3/4] getting ordinal num --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..80c6aefc5f 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -3,3 +3,12 @@ function getOrdinalNumber(num) { } module.exports = getOrdinalNumber; +// this is a code i came up with to get the ordinal number of a given number. +// I will now write tests to check if it works correctly. + +function getOrdinalNumber(n) { + const pr = new Intl.PluralRules("en-US", { type: "ordinal" }); + const suffixes = { one: "st", two: "nd", few: "rd", other: "th" }; + const rule = pr.select(n); + return `${n}${suffixes[rule]}`; +} \ No newline at end of file From 0e7fe7030bfe5100c58752b30395449b0160f7b3 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Fri, 10 Jul 2026 18:00:14 +0100 Subject: [PATCH 4/4] test.js for ordinal num --- .../2-practice-tdd/get-ordinal-number.test.js | 46 +++++++++++++++++++ 1 file changed, 46 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..4d3aac8eee 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,49 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); + +// here are more test cases for different scenarios + +const getOrdinalNumber = require("./get-ordinal-number"); + +describe("getOrdinalNumber", () => { + // Case 1: Already defined in your prompt + 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"); + }); + + // Case 2: Numbers ending with 2 (but not 12) + 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(142)).toEqual("142nd"); + }); + + // Case 3: Numbers ending with 3 (but not 13) + 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(153)).toEqual("153rd"); + }); + + // Case 4: Numbers ending with 11, 12, 13 (The exceptions) + test("should append 'th' for numbers ending in 11, 12, or 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"); + }); + + // Case 5: All other numbers + test("should append 'th' for all other numbers", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(20)).toEqual("20th"); + expect(getOrdinalNumber(34)).toEqual("34th"); + expect(getOrdinalNumber(100)).toEqual("100th"); + }); +}); \ No newline at end of file