Skip to content

Instantly share code, notes, and snippets.

@ferronrsmith
Created May 22, 2013 20:37
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferronrsmith/5630696 to your computer and use it in GitHub Desktop.
Save ferronrsmith/5630696 to your computer and use it in GitHub Desktop.
angular ordinal filter
'use strict';
// Ordinal Number Filter
// ---------------------
// This filter takes a number and returns its ordinal value
// i.e. 1 -> 1st, 2 -> 2nd, etc.
// h/t http://ecommerce.shopify.com/c/ecommerce-design/t/ordinal-number-in-javascript-1st-2nd-3rd-4th-29259
angular.module('ordinal', []).filter('ordinal', function() {
return function(input) {
var s=["th","st","nd","rd"],
v=input%100;
return input+(s[(v-20)%10]||s[v]||s[0]);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment