Skip to content

Commit 2e25623

Browse files
committed
feat: add ordinal suffix handling including special cases for 11, 12, and 13
1 parent a355524 commit 2e25623

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
function getOrdinalNumber(num) {
2-
return "1st";
2+
3+
const lastTwoDigits = num % 100;
4+
const lastDigit = num % 10
5+
6+
7+
if (lastTwoDigits === 11 || lastTwoDigits === 12 || lastTwoDigits === 13) {
8+
return num + "th";
9+
}
10+
11+
12+
if(lastDigit === 1) return num + "st";
13+
if(lastDigit === 2) return num + "nd";
14+
if(lastDigit === 3) return num + "rd";
15+
16+
return num + "th"
317
}
418

519
module.exports = getOrdinalNumber;

0 commit comments

Comments
 (0)