You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 lines
519 B
JavaScript
15 lines
519 B
JavaScript
5 years ago
|
function humanize(number) {
|
||
|
if(number % 100 >= 11 && number % 100 <= 13)
|
||
|
return number + "th";
|
||
|
|
||
|
switch(number % 10) {
|
||
|
case 1: return number + "st";
|
||
|
case 2: return number + "nd";
|
||
|
case 3: return number + "rd";
|
||
|
}
|
||
|
|
||
|
return number + "th";
|
||
|
}
|
||
|
console.log(humanize(1));
|
||
|
console.log(humanize(20));
|
||
|
console.log(humanize(302));
|