Last active
October 1, 2021 14:12
-
-
Save Mellen/d7238882db4a32b359c88cedc892228d to your computer and use it in GitHub Desktop.
For any non-negative integer, this function supplies the correct English ordinal suffix.
This file contains hidden or 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(n) | |
{ | |
let units = n % 10; | |
let tens = n % 100; | |
let ord = (units > 3 || units < 1) || (tens > 10 && tens < 20) ? 'th' : (units == 1 ? 'st' : (units == 2 ? 'nd' : 'rd')); | |
return ord; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment