Skip to content

Instantly share code, notes, and snippets.

@jakewtaylor
Last active February 27, 2019 10:39
Show Gist options
  • Save jakewtaylor/120eed6f0f49c098902c9d29628163c6 to your computer and use it in GitHub Desktop.
Save jakewtaylor/120eed6f0f49c098902c9d29628163c6 to your computer and use it in GitHub Desktop.
const ordinal = n => {
const options = ['th', 'st', 'nd', 'rd'];
const v = n % 100;
return options[(v - 20) % 10]
|| options[v]
|| options[0];
};
const ordinal = n => ['st', 'nd', 'rd'][((n + 90) % 100 - 10) % 10 - 1] || 'th';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment