Skip to content

Instantly share code, notes, and snippets.

@furf
Created July 6, 2009 15:06
Show Gist options
  • Save furf/141478 to your computer and use it in GitHub Desktop.
Save furf/141478 to your computer and use it in GitHub Desktop.
function ordinal (n) {
return['th','st','nd','rd'][(n=~~(n<0?-n:n)%100)>10&&n<14||(n%=10)>3?0:n];
}
var ordinal = function(n) {
n = parseInt(n, 10);
return (n > 10 && n < 20) ? 'th' : ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th'][n % 10];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment