Created
November 6, 2013 20:56
-
-
Save erberg-snippets/7343923 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
/** | |
* Returns the suffix related to the number for ex. (1st, 2nd, 3rd, 4th) | |
* @param {Number} number Number to find the suffix for. | |
* @return {String} Suffix string to append to be appended to number. | |
*/ | |
function getNumberSuffix(number) { | |
var numberConvertedToString = (number + ''); | |
var lastDigit = numberConvertedToString.charAt(numberConvertedToString.length - 1); | |
if (lastDigit === '1') { | |
var suffix = 'st'; | |
} else if (lastDigit === '2') { | |
var suffix = 'nd'; | |
} else if (lastDigit === '3') { | |
var suffix = 'rd'; | |
} else { | |
var suffix = 'th'; | |
} | |
return suffix; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment