Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e257518
intialise test for 0 occurrences character
leerogerfn Oct 12, 2026
eff24ad
written function for count.js
leerogerfn Oct 12, 2026
99fac63
written test for get-ordinal-number-test.js
leerogerfn Oct 12, 2026
f639c2f
written function for get-ordinal-number-test.js
leerogerfn Oct 12, 2026
3286ffc
written function for get-ordinal-number-test.js
leerogerfn Oct 14, 2026
490bddb
completed to write the tes for repeat-str.test
leerogerfn Oct 14, 2026
f77cde9
drafting the function of repeatStr.
leerogerfn Oct 14, 2026
83f7ae8
formatted document for count.js
leerogerfn Oct 14, 2026
92f3f60
written test for repeat-str.test.js
leerogerfn Oct 14, 2026
9a9f0f8
formatted document for repeat-str.js
leerogerfn Oct 14, 2026
dcee7f9
remove console.log in repeat-str.js
leerogerfn Oct 14, 2026
b4b909e
added test for char only exist in part of str for count.test.js
leerogerfn Oct 20, 2026
fc9bc09
added no occurrences in str with different char
leerogerfn Oct 20, 2026
5bcc595
change the wording on description of test.
leerogerfn Oct 20, 2026
1325473
added 111, 112, 113 for get-ordinal-number.test.js
leerogerfn Oct 20, 2026
051fef8
added "goodbye" to repeat-str.test.js
leerogerfn Oct 20, 2026
e18e1dc
added more test cases for "goodbye"
leerogerfn Oct 20, 2026
1a4e9e0
revised the function of get-ordinal-number.js
leerogerfn Oct 21, 2026
11f50bb
added empty string for count.test.js
leerogerfn Oct 22, 2026
f0b41af
revised test for 111, 112, 113 get-ordinal-number.test.js
leerogerfn Oct 22, 2026
c7be983
added empty str for get-ordinal-number.test.js
leerogerfn Oct 22, 2026
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
8 changes: 7 additions & 1 deletion practice-tdd/count.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export function countChar(stringOfCharacters, findCharacter) {
return 5
let count = 0;
for (let i = 0; i < stringOfCharacters.length; i++) {
if (stringOfCharacters[i] === findCharacter) {
count++;
}
}
return count;
}
22 changes: 22 additions & 0 deletions practice-tdd/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,25 @@ 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 no occurrences of a character", () => {
const str = "bbbbb";
const char = "a";
const count = countChar(str, char);
expect(count).toEqual(0);
});

test("should count multiple occurrences of a character which char only exist in some part of str", () => {
const str = "codeyourfuture";
const char = "u";
const count = countChar(str, char);
expect(count).toEqual(3);
});

test("should count no occurrences of no submission for str", () => {
const str = "";
const char = "q";
const count = countChar(str, char);
expect(count).toEqual(0);
});
17 changes: 16 additions & 1 deletion practice-tdd/get-ordinal-number.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
export function getOrdinalNumber(num) {
return "1st";
const numToString = num.toString();

if (
numToString.slice(-2) === "11" ||
numToString.slice(-2) === "12" ||
numToString.slice(-2) === "13"
) {
return `${num}th`;
} else if (numToString.at(-1) === "1") {
return `${num}st`;
} else if (numToString.at(-1) === "2") {
return `${num}nd`;
} else if (numToString.at(-1) === "3") {
return `${num}rd`;
}
return `${num}th`;
}
30 changes: 30 additions & 0 deletions practice-tdd/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,33 @@ 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 'nd' for numbers ending with 2, except those ending with 12", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
expect(getOrdinalNumber(22)).toEqual("22nd");
expect(getOrdinalNumber(132)).toEqual("132nd");
});

test("should append 'rd' for numbers ending with 3, except those ending with 13", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
expect(getOrdinalNumber(23)).toEqual("23rd");
expect(getOrdinalNumber(133)).toEqual("133rd");
});

test("should append 'th' for numbers 11/12/13", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(12)).toEqual("12th");
expect(getOrdinalNumber(13)).toEqual("13th");
});
Comment on lines +34 to +38

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

how about a larger number like 111?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

111 should be 111th but not 111st. Similar to 112th and 113th. Please fix them, thank you.


test("should append 'th' for the remaining number", () => {
expect(getOrdinalNumber(20)).toEqual("20th");
expect(getOrdinalNumber(35)).toEqual("35th");
expect(getOrdinalNumber(99)).toEqual("99th");
});

test("should append 'th' for numbers 111/112/113", () => {
expect(getOrdinalNumber(111)).toEqual("111th");
expect(getOrdinalNumber(112)).toEqual("112th");
expect(getOrdinalNumber(113)).toEqual("113th");
});
Loading
Loading