From 32407f92f9fd0ce28e3fba5ec44b26a38b344a5e Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Thu, 5 Mar 2026 09:52:22 +0000 Subject: [PATCH 1/4] Update .gitignore to include .vscode directory --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index bde36e530..a4da42080 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ node_modules .DS_Store -.vscode -**/.DS_Store \ No newline at end of file +.vscode/ +**/.DS_Store From 3f7a169adb570ccba1bad00b47b8f787c356bc44 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Mon, 9 Mar 2026 17:16:37 +0000 Subject: [PATCH 2/4] wrote function and tests for count --- Sprint-3/2-practice-tdd/count.js | 8 +++- Sprint-3/2-practice-tdd/count.test.js | 53 +++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..b3b0ce750 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,11 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + +let count = 0; +for (let char of stringOfCharacters) { + if (char === findCharacter) { + count++; + } } +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..c78404432 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,3 +22,56 @@ 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 count multiple occurrences of a character", () => { + const str = "aaaaa"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(5); +}); + +test("should count multiple occurrences of a character", () => { + const str = "blind"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); + +test("should count multiple occurrences of a character", () => { + const str = "blood"; + const char = "o"; + const count = countChar(str, char); + expect(count).toEqual(2); +}); + +test("should count multiple occurrences of a character", () => { + const str = "blood"; + const char = "o"; + const count = countChar(str, char); + expect(count).toEqual(2); +}); + +test("should count multiple occurrences of a character", () => { + const str = "blood"; + const char = "l"; + const count = countChar(str, char); + expect(count).toEqual(1); +}); + +test("should count multiple occurrences of a character", () => { + const str = "bbbrf"; + const char = "b"; + const count = countChar(str, char); + expect(count).toEqual(3); +}); + +test("should count multiple occurrences of a character", () => { + const str = "ooooa"; + const char = "o"; + const count = countChar(str, char); + expect(count).toEqual(4); +}); + +// handling invalid input +// the tests work assuming that only letters are in the string +// numbers and special characters are not tested for From 2c8e6276fb4f315af3eb7b4d06cf217a73a26331 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Mon, 9 Mar 2026 21:15:17 +0000 Subject: [PATCH 3/4] wrote function and tests for ordinal numbers --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 17 +++++++++- .../2-practice-tdd/get-ordinal-number.test.js | 32 +++++++++++++++++++ 2 files changed, 48 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..e4acc65bd 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,20 @@ function getOrdinalNumber(num) { - return "1st"; + // Check if input is a number + if (typeof num !== "number" || isNaN(num)) { + throw new Error("Input must be a valid number"); + } + + const j = num % 10; // checks what last number is + const k = num % 100; // checks what last two numbers are, needed to check for 11 + + if (k === 11 || k === 12 || k === 13) { + return num + "th"; + } + if (j === 1) return num + "st"; + if (j === 2) return num + "nd"; + if (j === 3) return num + "rd"; + + 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..6587afc5b 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -13,8 +13,40 @@ 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"); }); + +// Case 2: Numbers ending with 2 +// When the number ends with 2, +// Then the function should return a string by appending "nd" to the number. + +test("should append 'nd' for numbers ending with 2", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(32)).toEqual("32nd"); + expect(getOrdinalNumber(252)).toEqual("252nd"); +}); + +// Case 3: Numbers ending with 3 +// When the number ends with 3, +// Then the function should return a string by appending "rd" to the number. + +test("should append 'rd' for numbers ending with 3", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(33)).toEqual("33rd"); + expect(getOrdinalNumber(133)).toEqual("133rd"); +}); + +// Case 4: The remaining numbers +// When the number ends with 1, except those ending with 11 +// For all other numbers +// Then the function should return a string by appending "th" to the number. + +test("should append 'th' for remaining numbers", () => { + expect(getOrdinalNumber(20)).toEqual("20th"); + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(99)).toEqual("99th"); +}); From 3217cc5624c1211ebd565e17906cad30e0921ec6 Mon Sep 17 00:00:00 2001 From: Hayriye Saricicek Date: Tue, 10 Mar 2026 11:33:08 +0000 Subject: [PATCH 4/4] tests and function to repeat string --- Sprint-3/2-practice-tdd/repeat-str.js | 12 ++++++++++-- Sprint-3/2-practice-tdd/repeat-str.test.js | 22 +++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b00..7a21885ad 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,13 @@ -function repeatStr() { - return "hellohellohello"; +function repeatStr(str, count) { + if (count < 0) { + throw new Error("Count must be positive"); + } + + if (count === 0) { + return " "; + } + + return str.repeat(count); } 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..f4ba53e10 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, +// 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 throw an error when count is negative", () => { + const str = "hello"; + const count = -3; + expect(() => repeatStr(str, count)).toThrow("Count must be positive"); +});