Skip to content

Instantly share code, notes, and snippets.

@tristanm
Last active December 24, 2015 23:19
Show Gist options
  • Save tristanm/6879112 to your computer and use it in GitHub Desktop.
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.
# 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