Skip to content

Instantly share code, notes, and snippets.

@csandman
Created March 27, 2020 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csandman/e5e92734fa41e3d89b4ec008cd3b26cf to your computer and use it in GitHub Desktop.
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
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