Skip to content

Instantly share code, notes, and snippets.

@dubbs
Forked from redoPop/suffix.js
Last active December 17, 2015 02:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dubbs/5535349 to your computer and use it in GitHub Desktop.
Save dubbs/5535349 to your computer and use it in GitHub Desktop.
var suffix = function (n) {
n = n % 10;
return n > 3 ? 'th' : ['th', 'st', 'nd', 'rd'][n];
};
// suffix(1) => "st"
// suffix(102) => "nd"
// suffix(113) => "th"
@jamesplease
Copy link

11st
12nd
13rd

@Ehesp
Copy link

Ehesp commented Apr 3, 2014

This does not work well...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment