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.

17 lines
575 B
JavaScript

humanize_format = function humanize(num) {
if(typeof(num) == "undefined") return;
if(num % 100 >= 11 && num % 100 <= 13)
return num + "th";
switch(num % 10) {
case 1: return num + "st";
case 2: return num + "nd";
case 3: return num + "rd";
}
return num + "th";
}
console.log(humanize_format());
console.log(humanize_format(1));
console.log(humanize_format(8));
console.log(humanize_format(301));
console.log(humanize_format(402));