Created
May 22, 2013 20:37
-
-
Save ferronrsmith/5630696 to your computer and use it in GitHub Desktop.
angular ordinal filter
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
'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