/ord

Easily get the ordinal 'st', 'nd', 'rd' or 'th' of cardinal numbers.

Primary LanguageJavaScriptOtherNOASSERTION

 _______  _______  ______  
(  ___  )(  ____ )(  __  \ 
| (   ) || (    )|| (  \  )
| |   | || (____)|| |   ) |
| |   | ||     __)| |   | |
| |   | || (\ (   | |   ) |
| (___) || ) \ \__| (__/  )
(_______)|/   \__/(______/ 
                           

Gives you the 'st', 'nd', 'rd' or 'th' of a whole number.

Does not give you anything for zero, negative numbers, NaN, Infinity or real numbers (e.g. 3.14).

Does not give you anything for something which isn't a number.

Example

var a = 21;
console.log('Happy ' + a + ord(a));

Will print out 'Happy 21st'.

Author

Written by Andrew Chilton - Blog - Twitter.

License

Copyright 2013 Andrew Chilton. All rights reserved.

(Ends)