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
  • Select an option

  • Save dubbs/5535349 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown
11st
12nd
13rd

@Ehesp

Ehesp commented Apr 3, 2014

Copy link
Copy Markdown

This does not work well...

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