Skip to content

Commit 319f61b

Browse files
author
Ogbemi mene
committed
original number
1 parent ee6b85c commit 319f61b

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
1+
//function getOrdinalNumber(num) {
2+
//return "1st";
3+
//}
4+
5+
//module.exports = getOrdinalNumber;
16
function getOrdinalNumber(num) {
2-
return "1st";
7+
// Handle the teen exception rule first (11th, 12th, 13th)
8+
// Any number ending in 11, 12, or 13 gets a "th" suffix
9+
const lastTwoDigits = num % 100;
10+
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
11+
return num + "th";
12+
}
13+
14+
// Otherwise, look closely at the very last digit
15+
const lastDigit = num % 10;
16+
switch (lastDigit) {
17+
case 1:
18+
return num + "st";
19+
case 2:
20+
return num + "nd";
21+
case 3:
22+
return num + "rd";
23+
default:
24+
return num + "th";
25+
}
326
}
427

528
module.exports = getOrdinalNumber;

0 commit comments

Comments
 (0)