Skip to content
Closed
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;
}
Comment thread
asaniDev marked this conversation as resolved.

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`;
}
Comment thread
asaniDev marked this conversation as resolved.
Outdated
}

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");
Comment thread
asaniDev marked this conversation as resolved.
Outdated
});

test("should return any number between 4 and 20 with a suffix of 'th' at end of number", () => {
expect(getOrdinalNumber(10)).toEqual("10th");
});
Comment on lines +11 to 41
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are quite comprehensive. If you use this test script to test your implementation, you can discover some bug in your code.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added code to catch negative and non-integer values

Loading