Created
June 21, 2013 18:51
-
-
Save SaymV/5833429 to your computer and use it in GitHub Desktop.
JavaScript Ordinal Number Display
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
var ordinalNumberDisplay = function (number) { | |
var suffixes = ["th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"]; | |
switch (number % 100) { | |
case 11: | |
case 12: | |
case 13: | |
return number + "th"; | |
default: | |
return number + suffixes[number % 10]; | |
} | |
}; | |
alert(ordinalNumberDisplay(33)); //Alerts '33rd' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment