JSFiddle - React, Tailwind, and code Playground
JavaScript
function get_nth_suffix(date) {
switch (date) {
case 1:
case 21:
case 31:
return 'st';
case 2:
case 22:
return 'nd';
case 3:
case 23:
return 'rd';
default:
return 'th';
}
}
for (var i = 1; i < 32; ++i) {
document.write(i + get_nth_suffix(i) + '<br>');
}