Skip to content

Commit 0036b8d

Browse files
committed
the get-ordinal-number test is done
1 parent a135b88 commit 0036b8d

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
function getOrdinalNumber(num) {
2-
return "1st";
2+
const twoLastDig = num % 100;
3+
if (twoLastDig === 11 || twoLastDig === 12 || twoLastDig === 13) {
4+
return num + "th";
5+
}
6+
7+
const lastDig = num % 10;
8+
if (lastDig === 1) return num + "st";
9+
if (lastDig === 2) return num + "nd";
10+
if (lastDig === 3) return num + "rd";
11+
return num + "th";
312
}
413

14+
15+
16+
517
module.exports = getOrdinalNumber;

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,33 @@ const getOrdinalNumber = require("./get-ordinal-number");
1111
test("should return '1st' for 1", () => {
1212
expect(getOrdinalNumber(1)).toEqual("1st");
1313
});
14+
test("should return '11th' for 11", () => {
15+
expect(getOrdinalNumber(11)).toEqual("11th");
16+
});
17+
18+
test("should return '2nd' for 2", () => {
19+
expect(getOrdinalNumber(2)).toEqual("2nd");
20+
});
21+
22+
23+
test("should return '23rd' for 23rd", () => {
24+
expect(getOrdinalNumber(23)).toEqual("23rd");
25+
});
26+
test("should return '3rd' for 3", () => {
27+
expect(getOrdinalNumber(3)).toEqual("3rd");
28+
});
29+
test("should return '4th' for 4", () => {
30+
expect(getOrdinalNumber(4)).toEqual("4th");
31+
});
32+
33+
test("should return '12th' for 12", () => {
34+
expect(getOrdinalNumber(12)).toEqual("12th");
35+
});
36+
test("should return '13th' for 13", () => {
37+
expect(getOrdinalNumber(13)).toEqual("13th");
38+
});
39+
40+
41+
test("should return '101st' for 101", () => {
42+
expect(getOrdinalNumber(101)).toEqual("101st");
43+
});

0 commit comments

Comments
 (0)