Last active
August 29, 2015 14:02
-
-
Save ericnkatz/091058268087fff6b97f to your computer and use it in GitHub Desktop.
Javascript grab the ordinal number suffix. ie.) 1st, 2nd, 3rd, 4th, 21st, 32nd, 53rd, 60th, etc..
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
function ordinalSuffixOf(i) { | |
var j; | |
j = i % 10; | |
if (j === 1 && i !== 11) { | |
return i + 'st'; | |
} | |
if (j === 2 && i !== 12) { | |
return i + 'nd'; | |
} | |
if (j === 3 && i !== 13) { | |
return i + 'nd'; | |
} | |
return i + 'th'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment