Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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 pattern = new RegExp(findCharacter, "g");

let matchingChars = stringOfCharacters.match(pattern);

if (matchingChars === null) {
return 0;
}

return matchingChars.length;
}

module.exports = countChar;
6 changes: 6 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,9 @@ test("should count multiple occurrences of a character", () => {
// And a character char that does not exist within the case-sensitive str,
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.
test("should check for no occurrences of a character", () => {
const str = "abcdef";
const char = "g";
const count = countChar(str, char);
expect(count).toEqual(0);
});
11 changes: 10 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,14 @@
function getOrdinalNumber(num) {
return "1st";
if (num === 1) {
return "1st";
} else if (num === 2) {
return "2nd";
} else if (num === 3) {
console.log(num);
return "3rd";
} else if (num > 3 || num < 21) {
return `${num}th`;
}
}

module.exports = getOrdinalNumber;
12 changes: 12 additions & 0 deletions Sprint-3/2-practice-tdd/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@ const getOrdinalNumber = require("./get-ordinal-number");
test("should return '1st' for 1", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
});

test("should return '2nd' for 2", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
});

test("should return '3rd' for 3", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
});

test("should return any number between 4 and 20 with a suffix of 'th' at end of number", () => {
expect(getOrdinalNumber(10)).toEqual("10th");
});
Loading