Skip to content

Commit 2cb82aa

Browse files
committed
add more edge case for ordinal number checks
1 parent 30a0239 commit 2cb82aa

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Sprint-3/2-practice-tdd/get-ordinal-number.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ function getOrdinalNumber(num) {
33
const numLength = numStr.length;
44
if (numStr[numLength - 2] === "1" && numStr[numLength - 1] === "1") {
55
return num + "th";
6+
} else if (numStr[numLength - 2] === "1" && numStr[numLength - 1] === "2") {
7+
return num + "th";
68
} else if (numStr[numLength - 1] === "1") {
79
return num + "st";
810
} else if (numStr[numLength - 2] === "1" && numStr[numLength - 1] === "3") {

Sprint-3/2-practice-tdd/get-ordinal-number.test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,22 @@ test(" should return 'th' for numbers ending with 13", () => {
4141
expect(getOrdinalNumber(413)).toEqual("413th");
4242
expect(getOrdinalNumber(613)).toEqual("613th");
4343
});
44-
//case 4: expect number ending with 2 to return nd
44+
45+
//case:5 expect Numbers ending with 12 to return th
46+
test(" should return 'th' for numbers ending with 12", () => {
47+
expect(getOrdinalNumber(12)).toEqual("12th");
48+
expect(getOrdinalNumber(41)).toEqual("412th");
49+
expect(getOrdinalNumber(612)).toEqual("612th");
50+
});
51+
52+
//case 6: expect number ending with 2 to return nd
4553
test(" should return 'nd' for numbers ending with 2", () => {
4654
expect(getOrdinalNumber(22)).toEqual("22nd");
4755
expect(getOrdinalNumber(42)).toEqual("42nd");
4856
expect(getOrdinalNumber(102)).toEqual("102nd");
4957
});
5058

51-
// case 5: expect number not included in the above case to return th
59+
// case 7: expect number not included in the above case to return th
5260
test("should return 'th' for numbers ending with 4, 5,6,7,8,9,0", () => {
5361
expect(getOrdinalNumber(4)).toEqual("4th");
5462
expect(getOrdinalNumber(5)).toEqual("5th");

0 commit comments

Comments
 (0)