Skip to content

Commit 22f8e4a

Browse files
implemented how special ordinal number cases like 11,12,13 are handled by making sure they always end in "th"
1 parent 5f2aa2c commit 22f8e4a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
function getOrdinalNumber(num) {
2-
return "1st";
2+
const lastTwoDigits = num % 100; // gets the last two digits of the number because some like 11, 12, 13 are special cases.
3+
const lastDigit= num % 10; // gets the last digit to decide if its going to be "St, Nd, Rd"
4+
5+
// handles special cases like "11,12,13" to always end in the "Th"
6+
if (lastTwoDigits === 11 || lastTwoDigits === 12 || lastTwoDigits === 13){
7+
return num + "St";
8+
}
9+
310
}
411

512
module.exports = getOrdinalNumber;

0 commit comments

Comments
 (0)