Created
November 15, 2016 21:33
-
-
Save narainsagar/ad54a08fdd1162b355480e6d4c63e8b3 to your computer and use it in GitHub Desktop.
Ordinal numbers
This file contains hidden or 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
| function ordinalParse() { | |
| return /\d{1,2}(st|nd|rd|th)/; | |
| } | |
| function ordinal(number) { | |
| var b = number % 10, | |
| output = (~~(number % 100 / 10) === 1) ? 'th' : | |
| (b === 1) ? 'st' : | |
| (b === 2) ? 'nd' : | |
| (b === 3) ? 'rd' : 'th'; | |
| return number + output; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment