Created
          February 24, 2010 19:39 
        
      - 
      
- 
        Save redoPop/313766 to your computer and use it in GitHub Desktop. 
    JavaScript: integer suffixes (1st, 2nd, 3rd...)
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var suffix = function(n) { | |
| var d = (n|0)%100; | |
| return d > 3 && d < 21 ? 'th' : ['th', 'st', 'nd', 'rd'][d%10] || 'th'; | |
| }; | |
| // suffix(1) => "st" | |
| // suffix(102) => "nd" | |
| // suffix(113) => "th" | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Thanks for the gist, I have an updated version here:
https://gist.github.com/dubbs/5535349