Skip to content

Instantly share code, notes, and snippets.

@i8ramin
Created June 20, 2013 18:40
Show Gist options
  • Select an option

  • Save i8ramin/5825413 to your computer and use it in GitHub Desktop.

Select an option

Save i8ramin/5825413 to your computer and use it in GitHub Desktop.
Add this to digits and get the ordinal representation like 1st, 2nd 3rd, 113th, etc. (logic borrowed from Rails ordinalize helper)
(function () {
'use strict';
angular.module('ConferenceRoomApp').filter('ordinalize', function () {
return function (number) {
var res = number.toString();
if (/(11|12|13)/.test(Math.abs(number) % 100)) {
res = number + 'th';
} else {
switch(number) {
case 1:
res = number + 'st';
break;
case 2:
res = number + 'nd';
break;
case 3:
res = number + 'rd';
break;
default:
res = number + 'th';
}
}
return res;
};
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment