Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Sprint-3/2-practice-tdd/count.js
Original file line number Diff line number Diff line change
@@ -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;
18 changes: 18 additions & 0 deletions Sprint-3/2-practice-tdd/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,21 @@ 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 return 0 when the character does not occur in the string", () => {
const str = "hello world";
const char = "x";
const count = countChar(str, char);
expect(count).toEqual(0);
});

// Scenario: Case Sensitivity
// Given the input string `str`,
// And a character `char` that occurs in `str` but with different cases (e.g., 'a' and 'A'),
// When the function is called with these inputs,
// Then it should count only the occurrences of `char` that match the case provided in the input.
test("should count only occurrences of the character that match the case", () => {
const str = "AaAaA";
const char = "a";
const count = countChar(str, char);
expect(count).toEqual(2);
});
19 changes: 18 additions & 1 deletion Sprint-3/2-practice-tdd/get-ordinal-number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
function getOrdinalNumber(num) {
return "1st";
const lastDigit = num % 10;
const lastTwoDigits = num % 100;

if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
return `${num}th`;
}

switch (lastDigit) {
case 1:
return `${num}st`;
case 2:
return `${num}nd`;
case 3:
return `${num}rd`;
default:
return `${num}th`;
}
}

module.exports = getOrdinalNumber;

1 change: 1 addition & 0 deletions Sprint-3/2-practice-tdd/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ test("should append 'st' for numbers ending with 1, except those ending with 11"
expect(getOrdinalNumber(21)).toEqual("21st");
expect(getOrdinalNumber(131)).toEqual("131st");
});

2 changes: 2 additions & 0 deletions Sprint-3/2-practice-tdd/repeat-str.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ function repeatStr() {
}

module.exports = repeatStr;


2 changes: 2 additions & 0 deletions Sprint-3/2-practice-tdd/repeat-str.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ 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.


Loading