Created
March 27, 2020 21:32
-
-
Save csandman/e5e92734fa41e3d89b4ec008cd3b26cf to your computer and use it in GitHub Desktop.
A function to get a number string with the ordinal suffix in JS
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 getNumberWithOrdinal(n) { | |
const s = ["th", "st", "nd", "rd"]; | |
const v = n % 100; | |
return n + (s[(v - 20) % 10] || s[v] || s[0]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment