Advertisement
reddaigo

Untitled

Apr 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. function suffix(num) {
  2. var suffixDict = { 1 : "st", 2 : "nd", 3 : "rd"};
  3. var singleDigit = num % 10;
  4. var tensDigit = (Math.floor(num/10) % 10);
  5. if (tensDigit != 1 && singleDigit in suffixDict) {
  6. return num + suffixDict[singleDigit];
  7. }
  8. else {
  9. return num + "th";
  10. }
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement