Yes, yes, I know, 2000 should return "21st" century. I don't know of anyone who counts centuries like that, so my function returns them according to normal use.
const addBC = year => year < 0 ? " BC" : "" const centurify = year => { const num = Math.ceil(Math.abs(year) / 100).toString() const suffix = num.match(/(11|12|13)$/) ? "th" : num.endsWith("1") ? "st" : num.endsWith("2") ? "nd" : num.endsWith("3") ? "rd" : "th" return num + suffix + addBC(year) }
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.
Yes, yes, I know, 2000 should return "21st" century. I don't know of anyone who counts centuries like that, so my function returns them according to normal use.