Skip to content

Instantly share code, notes, and snippets.

@Xophmeister
Last active December 10, 2015 13:48
Show Gist options
  • Save Xophmeister/4442858 to your computer and use it in GitHub Desktop.
Save Xophmeister/4442858 to your computer and use it in GitHub Desktop.
JavaScript ordinals
Number.prototype.ordinal = function() {
return this < 0 ? undefined
: this + ['th', 'st', 'nd', 'rd'][this % 10 < 4 ? (this % 10) * (parseInt(this / 10, 10) % 10 == 1 ? 0 : 1) : 0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment