Skip to content

Instantly share code, notes, and snippets.

@djheru
Created February 28, 2014 18:47
Show Gist options
  • Save djheru/9277120 to your computer and use it in GitHub Desktop.
Save djheru/9277120 to your computer and use it in GitHub Desktop.
Formatter for numbers like 1st, 2nd, 3rd, 4th, etc (Ordinal Number Suffix)
var ons = function (n) {return n < 11 || n > 13 ? ['st', 'nd', 'rd', 'th'][Math.min((n - 1) % 10, 3)] : 'th'};
for(var i=1; i <= 100; i++){ console.log(i + '' + ons(i)); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment