diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..cd9d2d9348 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 +// } function countChar(stringOfCharacters, findCharacter) { - return 5 + let countChar = 0; + for (let stringNum = 0; stringNum < stringOfCharacters.length; stringNum++) { + if (findCharacter === stringOfCharacters[stringNum]){ + countChar++ + } + } + return countChar } - module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf7..b5761020b0 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -17,8 +17,29 @@ test("should count multiple occurrences of a character", () => { expect(count).toEqual(5); }); +test("should count multiple occurrences of a character", () => { + const str = "aaa aa"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(5); +}); + +test("should count multiple occurrences of a character with random characters", () => { + const str = "ajhyabhaakaka"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(6); +}) + // 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. +test("should return 0 with no occurrence of the character", () => { + const str ="abcd"; + const char = "e"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); + diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..ad65497f4a 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,14 @@ +// function getOrdinalNumber(num) { +// return "1st"; +// } + function getOrdinalNumber(num) { - return "1st"; + let text = num.toString(); + if (text === "11") { + return (text + "th"); + } + return (text + "st"); } +// getOrdinalNumber(1)).toEqual("1st") 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 adfa58560f..1cf5ac1d18 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,8 @@ 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 'th' for number 11", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + +}); \ No newline at end of file