Last active
August 29, 2015 14:06
-
-
Save leftis/8b43cda4ae8bfe4b4bf6 to your computer and use it in GitHub Desktop.
This file contains 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
Number.prototype.ordinate = function(){ | |
var num = this, | |
numStr = num.toString(), | |
last = numStr.slice(-1), | |
len = numStr.length, | |
ord = ''; | |
switch (last) { | |
case '1': | |
ord = numStr.slice(-2) === '11' ? 'th' : 'st'; | |
break; | |
case '2': | |
ord = numStr.slice(-2) === '12' ? 'th' : 'nd'; | |
break; | |
case '3': | |
ord = numStr.slice(-2) === '13' ? 'th' : 'rd'; | |
break; | |
default: | |
ord = 'th'; | |
break; | |
} | |
return num.toString() + ord; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment