From a75974d40b2a9089e9de6e59bc3bfe988ac0543e Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Fri, 20 Feb 2026 06:38:00 +0000 Subject: [PATCH 1/5] completed_Practice_TDD --- Sprint-3/2-practice-tdd/count.js | 7 ++++- Sprint-3/2-practice-tdd/count.test.js | 6 ++++ Sprint-3/2-practice-tdd/get-ordinal-number.js | 16 ++++++++++- .../2-practice-tdd/get-ordinal-number.test.js | 28 +++++++++++++++++++ Sprint-3/2-practice-tdd/repeat-str.js | 5 ++-- Sprint-3/2-practice-tdd/repeat-str.test.js | 20 +++++++++++++ package.json | 6 ++-- 7 files changed, 81 insertions(+), 7 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..9e7d28e30 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,10 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0; + for (char of stringOfCharacters) { + if (char === findCharacter) { + count = count + 1; + }} + return count; } module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf..8cd36fb68 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -16,6 +16,12 @@ test("should count multiple occurrences of a character", () => { const count = countChar(str, char); expect(count).toEqual(5); }); +test("No Occurrences", () => { + const str = "qwerty"; + const char = "k"; + const count = countChar(str, char); + expect(count).toEqual(0); +}) // Scenario: No Occurrences // Given the input string `str`, diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db1..aebbeabc4 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,19 @@ function getOrdinalNumber(num) { - return "1st"; + let last2digit = num % 100 + let lastDigit = num % 10 + if (last2digit === 11 || last2digit === 12 || last2digit === 13) { + return `${num}th` + } + else if (lastDigit === 1) { + return `${num}st` + } + else if (lastDigit === 2) { + return `${num}nd` + } + else if (lastDigit === 3) { + return `${num}rd` + } + else return `${num}th` } 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 adfa58560..f12033352 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,32 @@ 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(11)).toEqual("11th"); + expect(getOrdinalNumber(111)).toEqual("111th"); }); + +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(12)).toEqual("12th"); + expect(getOrdinalNumber(112)).toEqual("112th"); +}); + +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(13)).toEqual("13th"); + expect(getOrdinalNumber(113)).toEqual("113th"); +}); + +test("should append 'th' for all other numbers", () => { + expect(getOrdinalNumber(0)).toEqual("0th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(14)).toEqual("14th"); + expect(getOrdinalNumber(19)).toEqual("19th"); + expect(getOrdinalNumber(99)).toEqual("99th"); + expect(getOrdinalNumber(1000)).toEqual("1000th"); +}); + diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b00..8be71f15d 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,6 @@ -function repeatStr() { - return "hellohellohello"; +function repeatStr(str, count) { + if (count >= 0) {return str.repeat(count)} + else throw new Error("Error") } 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 a3fc1196c..f4eebae1f 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 repeat the string count times", () => { + 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 repeat the string count times", () => { + 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 repeat the string count times", () => { + const str = "hello"; + const count = -1; + expect(function(){repeatStr(str, count)}).toThrow() +}); \ No newline at end of file diff --git a/package.json b/package.json index 0657e22dd..87d27ab8f 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "keywords": [], "author": "Code Your Future", "license": "ISC", - "dependencies": { - "jest": "^29.7.0" + "devDependencies": { + "jest": "^30.2.0" } -} \ No newline at end of file +} From 197be8909f5cfc06b977340429b1c4978c1d6fbd Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Sat, 21 Feb 2026 08:43:38 +0000 Subject: [PATCH 2/5] completed-dead-code --- Sprint-3/3-dead-code/exercise-1.js | 2 +- Sprint-3/3-dead-code/exercise-2.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js index 4d09f15fa..d9d3f9f48 100644 --- a/Sprint-3/3-dead-code/exercise-1.js +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -7,7 +7,7 @@ const greeting = "hello"; function sayHello(greeting, name) { const greetingStr = greeting + ", " + name + "!"; return `${greeting}, ${name}!`; - console.log(greetingStr); + //console.log(greetingStr); } testName = "Aman"; diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js index 56d7887c4..021f1f989 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -14,8 +14,8 @@ function countAndCapitalisePets(petsArr) { petsArr.forEach((pet) => { const capitalisedPet = pet.toUpperCase(); - if (petCount[capitalisedPet]) { - petCount[capitalisedPet] += 1; + // if (petCount[capitalisedPet]) { + // petCount[capitalisedPet] += 1; } else { petCount[capitalisedPet] = 1; } From 712b964b597f7c73de7bef1fd540712827a39b00 Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Sat, 21 Feb 2026 08:55:00 +0000 Subject: [PATCH 3/5] fixed-dead-code --- Sprint-3/3-dead-code/exercise-2.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js index 021f1f989..369287b02 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -2,7 +2,7 @@ // The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; -const capitalisedPets = pets.map((pet) => pet.toUpperCase()); +//const capitalisedPets = pets.map((pet) => pet.toUpperCase()); const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); function logPets(petsArr) { @@ -14,8 +14,8 @@ function countAndCapitalisePets(petsArr) { petsArr.forEach((pet) => { const capitalisedPet = pet.toUpperCase(); - // if (petCount[capitalisedPet]) { - // petCount[capitalisedPet] += 1; + if (petCount[capitalisedPet]) { + petCount[capitalisedPet] += 1; } else { petCount[capitalisedPet] = 1; } From 8faba0693f2d021428aa0f131eafc344da19650f Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Sat, 21 Feb 2026 09:04:36 +0000 Subject: [PATCH 4/5] changes removed from dead code files --- Sprint-3/3-dead-code/exercise-1.js | 2 +- Sprint-3/3-dead-code/exercise-2.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js index d9d3f9f48..4d09f15fa 100644 --- a/Sprint-3/3-dead-code/exercise-1.js +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -7,7 +7,7 @@ const greeting = "hello"; function sayHello(greeting, name) { const greetingStr = greeting + ", " + name + "!"; return `${greeting}, ${name}!`; - //console.log(greetingStr); + console.log(greetingStr); } testName = "Aman"; diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js index 369287b02..d62de2b34 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -2,7 +2,7 @@ // The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; -//const capitalisedPets = pets.map((pet) => pet.toUpperCase()); +const capitalisedPets = pets.map((pet) => pet.toUpperCase()); const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); function logPets(petsArr) { From 75dfc4b3f27bcf336b499693a5aa227e17086f9e Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Sat, 21 Feb 2026 10:06:55 +0000 Subject: [PATCH 5/5] return-previous-version-of-files --- Sprint-3/3-dead-code/exercise-2.js | 4 ++-- package.json | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js index d62de2b34..56d7887c4 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -14,8 +14,8 @@ function countAndCapitalisePets(petsArr) { petsArr.forEach((pet) => { const capitalisedPet = pet.toUpperCase(); - if (petCount[capitalisedPet]) { - petCount[capitalisedPet] += 1; + if (petCount[capitalisedPet]) { + petCount[capitalisedPet] += 1; } else { petCount[capitalisedPet] = 1; } diff --git a/package.json b/package.json index 87d27ab8f..0657e22dd 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "keywords": [], "author": "Code Your Future", "license": "ISC", - "devDependencies": { - "jest": "^30.2.0" + "dependencies": { + "jest": "^29.7.0" } -} +} \ No newline at end of file