Skip to content

Commit 3716573

Browse files
authored
Implement getOrdinalNumber function logic
1 parent 0f76821 commit 3716573

File tree

1 file changed

+14
-0
lines changed

1 file changed

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

519
module.exports = getOrdinalNumber;

0 commit comments

Comments
 (0)