function thuffix(n) { let ending = 'th'; if(n%100 != 11 && n%100 != 12 && n%100 != 13) { if(n%10 == 1) { ending = 'st'; } else if(n%10 == 2) { ending = 'nd'; } else if(n%10 == 3) { ending = 'rd'; } } return ending; } function getCentury(year) { let c = Math.floor(year/100); if(year%100 != 0) { c++; } return `${c}${thuffix(c)}`; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Discussion on: Daily Challenge #296 - Years to Centuries
For further actions, you may consider blocking this person and/or reporting abuse