From b54e16e14d98d052453d1c389d04504d414c88d9 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Sat, 27 Jun 2026 14:00:49 +0200 Subject: [PATCH 01/15] count.js --- Sprint-3/2-practice-tdd/count.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..7f8190b7a4 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,21 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + return 5; +} + +module.exports = countChar; + +// fixed version of the function + +function countChar(stringOfCharacters, findCharacter) { + let count = 0; + + for (let char of stringOfCharacters) { + if (char === findCharacter) { + count++; + } + } + + return count; } module.exports = countChar; From 4175a5d7ad3e2b1b0410b92d08fe4d28b971410b Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Sat, 27 Jun 2026 14:02:57 +0200 Subject: [PATCH 02/15] count.test.js --- Sprint-3/2-practice-tdd/count.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf7..d1b6300663 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,3 +22,5 @@ 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. + +// From ac872ce422aebec9f99a6bd6c670658d341a4dbb Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Sat, 27 Jun 2026 14:03:24 +0200 Subject: [PATCH 03/15] count.test --- Sprint-3/2-practice-tdd/count.test.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index d1b6300663..54e986fa26 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -23,4 +23,26 @@ test("should count multiple occurrences of a character", () => { // When the function is called with these inputs, // Then it should return 0, indicating that no occurrences of `char` were found. -// +//completed version + +const countChar = require("./countChar"); + +// Scenario: Multiple Occurrences +test("should count multiple occurrences of a character", () => { + const str = "aaaaa"; + const char = "a"; + + const count = countChar(str, char); + + expect(count).toEqual(5); +}); + +// Scenario: No Occurrences +test("should return 0 when character is not found", () => { + const str = "hello"; + const char = "z"; + + const count = countChar(str, char); + + expect(count).toEqual(0); +}); From 8f2c7fab427b0368d7647514c00c182691b6fa8c Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Sat, 27 Jun 2026 14:05:03 +0200 Subject: [PATCH 04/15] ordinal-numbers --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 19 +++++++++++++++++++ 1 file changed, 19 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..d34c6236cd 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -3,3 +3,22 @@ function getOrdinalNumber(num) { } module.exports = getOrdinalNumber; + +//correct version of the function + +function getOrdinalNumber(num) { + const lastDigit = num % 10; + const lastTwoDigits = num % 100; + + if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { + return num + "th"; + } + + if (lastDigit === 1) return num + "st"; + if (lastDigit === 2) return num + "nd"; + if (lastDigit === 3) return num + "rd"; + + return num + "th"; +} + +module.exports = getOrdinalNumber; From 7ff81d8125061c8cb6bf04697f4315379725b0a0 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Sat, 27 Jun 2026 14:09:30 +0200 Subject: [PATCH 05/15] ordinal number test --- .../2-practice-tdd/get-ordinal-number.test.js | 35 +++++++++++++++++++ 1 file changed, 35 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..9a89b3f6bb 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,38 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); + +//fixed and completed version + +const getOrdinalNumber = require("./get-ordinal-number"); + +// st cases (except 11) +test("should return 'st' for numbers ending in 1 except 11", () => { + expect(getOrdinalNumber(1)).toEqual("1st"); + expect(getOrdinalNumber(21)).toEqual("21st"); + expect(getOrdinalNumber(31)).toEqual("31st"); +}); + +// nd cases (except 12) +test("should return 'nd' for numbers ending in 2 except 12", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(22)).toEqual("22nd"); + expect(getOrdinalNumber(32)).toEqual("32nd"); +}); + +// rd cases (except 13) +test("should return 'rd' for numbers ending in 3 except 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(33)).toEqual("33rd"); +}); + +// th cases (everything else) +test("should return 'th' for numbers ending in 4-9 and special teens (11-13)", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); + expect(getOrdinalNumber(14)).toEqual("14th"); + expect(getOrdinalNumber(100)).toEqual("100th"); +}); From 53b66214fdb7be535551a9406030ad26dfa853df Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Wed, 15 Jul 2026 13:22:05 +0200 Subject: [PATCH 06/15] repeat js --- Sprint-3/2-practice-tdd/repeat-str.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 2af0a2cea7..80ed22086b 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -5,3 +5,17 @@ function repeatStr() { } module.exports = repeatStr; + +//fixed + +function repeatStr(str, count) { + let result = ""; + + for (let i = 0; i < count; i++) { + result += str; + } + + return result; +} + +module.exports = repeatStr; From 09d914f3cd0dbc5a215ee220b9e7b465e138ee8f Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Wed, 15 Jul 2026 13:26:55 +0200 Subject: [PATCH 07/15] repeat-str.test.js --- Sprint-3/2-practice-tdd/repeat-str.test.js | 25 ++++++++++++++++++++++ 1 file changed, 25 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..262dd52f87 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -30,3 +30,28 @@ test("should repeat the string count times", () => { // 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 return the original string when count is 1", () => { + const str = "hello"; + const count = 1; + + const repeatedStr = repeatStr(str, count); + + expect(repeatedStr).toEqual("hello"); +}); + +test("should return an empty string when count is 0", () => { + const str = "hello"; + const count = 0; + + const repeatedStr = repeatStr(str, count); + + expect(repeatedStr).toEqual(""); +}); + +test("should throw an error when count is negative", () => { + const str = "hello"; + const count = -1; + + expect(() => repeatStr(str, count)).toThrow(); +}); From e33479b1c953709c17af23b9c9c3bfc9f9a7ef78 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Sat, 1 Aug 2026 10:21:44 +0200 Subject: [PATCH 08/15] jest --- Sprint-3/2-practice-tdd/repeat-str.test.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index 262dd52f87..0e0935f04d 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -31,25 +31,21 @@ test("should repeat the string count times", () => { // When the repeatStr function is called with these inputs, // Then it should throw an error, as negative counts are not valid. -test("should return the original string when count is 1", () => { +test("should repeat the string 1 time", () => { const str = "hello"; const count = 1; - const repeatedStr = repeatStr(str, count); - expect(repeatedStr).toEqual("hello"); }); -test("should return an empty string when count is 0", () => { +test("should not repeat the string", () => { const str = "hello"; const count = 0; - const repeatedStr = repeatStr(str, count); - expect(repeatedStr).toEqual(""); }); -test("should throw an error when count is negative", () => { +test("should throw an error for negative count", () => { const str = "hello"; const count = -1; From 040f91d62956184c75941a7f58620beb7b2832b5 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Sat, 1 Aug 2026 10:32:29 +0200 Subject: [PATCH 09/15] error --- Sprint-3/2-practice-tdd/repeat-str.test.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index 0e0935f04d..f23204e499 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -9,13 +9,6 @@ const repeatStr = require("./repeat-str"); // When the repeatStr function is called with these inputs, // 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"); -}); - // 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, From f4e8bed23f732bb487404b7b1ed4da2788d0c30e Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Sat, 1 Aug 2026 10:42:41 +0200 Subject: [PATCH 10/15] fix --- Sprint-3/2-practice-tdd/repeat-str.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 80ed22086b..2fd0a1cb46 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,13 +1,3 @@ -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"; -} - -module.exports = repeatStr; - -//fixed - function repeatStr(str, count) { let result = ""; From fa3354aa292e8b7d18fc226f519364e330edc53f Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Sat, 1 Aug 2026 10:46:49 +0200 Subject: [PATCH 11/15] fix --- Sprint-3/2-practice-tdd/repeat-str.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 2fd0a1cb46..48679b224e 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,4 +1,8 @@ function repeatStr(str, count) { + if (count < 0) { + throw new Error("Count cannot be negative"); + } + let result = ""; for (let i = 0; i < count; i++) { From 24f34c63830fdef5d67096a617052adac9ac9204 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Sat, 1 Aug 2026 11:14:45 +0200 Subject: [PATCH 12/15] ordinal --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 6 ------ 1 file changed, 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 d34c6236cd..1a96d2661a 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,9 +1,3 @@ -function getOrdinalNumber(num) { - return "1st"; -} - -module.exports = getOrdinalNumber; - //correct version of the function function getOrdinalNumber(num) { From b1aa6bf0d1563b9e0e28c473560e787c38f38c71 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Sat, 1 Aug 2026 11:15:36 +0200 Subject: [PATCH 13/15] fix --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 6 ------ 1 file changed, 6 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 9a89b3f6bb..0c1187e0a8 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -1,4 +1,3 @@ -const getOrdinalNumber = require("./get-ordinal-number"); // In this week's prep, we started implementing getOrdinalNumber. // Continue testing and implementing getOrdinalNumber for additional cases. @@ -13,11 +12,6 @@ const getOrdinalNumber = require("./get-ordinal-number"); // Case 1: Numbers ending with 1 (but not 11) // When the number ends with 1, except those ending with 11, // Then the function should return a string by appending "st" to the number. -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"); -}); //fixed and completed version From d8b133a4a8fbf4193d2b00830ffdb98ce09b57d9 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Sat, 1 Aug 2026 11:23:39 +0200 Subject: [PATCH 14/15] count js --- Sprint-3/2-practice-tdd/count.js | 6 ------ Sprint-3/2-practice-tdd/count.test.js | 27 --------------------------- 2 files changed, 33 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 7f8190b7a4..71cb562ca2 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,9 +1,3 @@ -function countChar(stringOfCharacters, findCharacter) { - return 5; -} - -module.exports = countChar; - // fixed version of the function function countChar(stringOfCharacters, findCharacter) { diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 54e986fa26..62fbe100ce 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -1,30 +1,3 @@ -// implement a function countChar that counts the number of times a character occurs in a string -const countChar = require("./count"); -// Given a string `str` and a single character `char` to search for, -// When the countChar function is called with these inputs, -// Then it should: - -// Scenario: Multiple Occurrences -// Given the input string `str`, -// And a character `char` that occurs one or more times in `str` (e.g., 'a' in 'aaaaa'), -// When the function is called with these inputs, -// Then it should correctly count occurrences of `char`. - -test("should count multiple occurrences of a character", () => { - const str = "aaaaa"; - const char = "a"; - const count = countChar(str, char); - expect(count).toEqual(5); -}); - -// 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. - -//completed version - const countChar = require("./countChar"); // Scenario: Multiple Occurrences From 9c36da78c9990462542469e477471e4354d18e2a Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Sat, 1 Aug 2026 11:50:29 +0200 Subject: [PATCH 15/15] update --- Sprint-3/2-practice-tdd/count.test.js | 17 +++-------------- .../2-practice-tdd/{count.js => countChar.js} | 6 ++---- 2 files changed, 5 insertions(+), 18 deletions(-) rename Sprint-3/2-practice-tdd/{count.js => countChar.js} (57%) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 62fbe100ce..49cf2eeff3 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -1,19 +1,8 @@ const countChar = require("./countChar"); -// Scenario: Multiple Occurrences -test("should count multiple occurrences of a character", () => { - const str = "aaaaa"; - const char = "a"; - - const count = countChar(str, char); - - expect(count).toEqual(5); -}); - -// Scenario: No Occurrences -test("should return 0 when character is not found", () => { - const str = "hello"; - const char = "z"; +test("should return 0 when character does not exist in the string", () => { + const str = "hello world"; + const char = "x"; const count = countChar(str, char); diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/countChar.js similarity index 57% rename from Sprint-3/2-practice-tdd/count.js rename to Sprint-3/2-practice-tdd/countChar.js index 71cb562ca2..79977793e5 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/countChar.js @@ -1,10 +1,8 @@ -// fixed version of the function - function countChar(stringOfCharacters, findCharacter) { let count = 0; - for (let char of stringOfCharacters) { - if (char === findCharacter) { + for (let i = 0; i < stringOfCharacters.length; i++) { + if (stringOfCharacters[i] === findCharacter) { count++; } }