Last active
July 25, 2019 08:06
-
-
Save b-bot/7a4a4b566a06f2db83a77528839e46ca to your computer and use it in GitHub Desktop.
Get the ordinal suffix for any number you want converted to a day. ie. suffixes -st, -nd, -rd, -th in written ordinals (represented as 1st, 2nd, 3rd, 4th)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ordinalSuffix(i) { | |
const j = i % 10, | |
k = i % 100; | |
if (j === 1 && k !== 11) { | |
return i + 'st'; | |
} | |
if (j === 2 && k !== 12) { | |
return i + 'nd'; | |
} | |
if (j === 3 && k !== 13) { | |
return i + 'rd'; | |
} | |
return i + 'th'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment