Created
August 23, 2016 20:14
-
-
Save Stanback/ad88d76c454f5c9962010f60abe2bee3 to your computer and use it in GitHub Desktop.
Convert integer to an ordinal number (e.g. 1st, 2nd, 3rd, etc)
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 getOrdinal(value) { | |
const suffixes = ['th', 'st', 'nd', 'rd']; | |
const normalized = value % 100; | |
return value + (suffixes[(normalized - 20) % 10] || suffixes[normalized] || suffixes[0]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment