Skip to content

Instantly share code, notes, and snippets.

@ericnkatz
Last active August 29, 2015 14:02
Show Gist options
  • Save ericnkatz/091058268087fff6b97f to your computer and use it in GitHub Desktop.
Save ericnkatz/091058268087fff6b97f to your computer and use it in GitHub Desktop.
Javascript grab the ordinal number suffix. ie.) 1st, 2nd, 3rd, 4th, 21st, 32nd, 53rd, 60th, etc..
function ordinalSuffixOf(i) {
var j;
j = i % 10;
if (j === 1 && i !== 11) {
return i + 'st';
}
if (j === 2 && i !== 12) {
return i + 'nd';
}
if (j === 3 && i !== 13) {
return i + 'nd';
}
return i + 'th';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment