Skip to content

Instantly share code, notes, and snippets.

@countable
Last active October 9, 2015 06:28
Show Gist options
  • Save countable/3454241 to your computer and use it in GitHub Desktop.
Save countable/3454241 to your computer and use it in GitHub Desktop.
Convert numbers to ordinal form. ie) 1,2,3,4,...N to '1st', '2nd', '3rd', '4th',...'Nth'
/* ordinal(n)
* @param {number} n - the number to output an ordinal for.
* Convert numbers to ordinal form. ie) 1,2,3,4,...N to '1st', '2nd', '3rd', '4th',...'Nth'
*/
ordinal = function(n) {
if (n === 1) {
n += 'st';
} else if (n === 2) {
n += 'nd';
} else if (n === 3) {
n += 'rd';
} else {
n += 'th';
}
return n;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment