Last active
December 24, 2015 23:19
-
-
Save tristanm/6879112 to your computer and use it in GitHub Desktop.
AngularJS filter for ordinalising a number. Not thoroughly tested. Known not to work for 11, 12 and 13.
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
# Credit to https://github.com/jdpedrie/angularjs-ordinal-filter (which also doesn't work for 11, 12 and 13) | |
ghostBooking.filter "ordinal", -> | |
(number) -> | |
suffixes = ["th", "st", "nd", "rd"] | |
value = number % 100 # The last two digits, e.g. 12345 % 100 => 45 | |
number + (suffixes[(l2d - 20) % 10] || suffixes[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment