Last active
December 10, 2015 13:48
-
-
Save Xophmeister/4442858 to your computer and use it in GitHub Desktop.
JavaScript ordinals
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
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