I like your approach, it looks very clean.
This is probably too fringe to matter in most contexts, but wouldn't your function return 111st for the year 11,092?
It would, indeed. Thanks for pointing out. Now I have fixed it and added a new test case.
OLD SOLUTION (Line 7)
const suffix = Math.floor(cent / 10) === 1 ? 'th'
UPDATED SOLUTION (Line 7)
const suffix = Math.floor(cent / 10) % 10 === 1 ? 'th'
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.
I like your approach, it looks very clean.
This is probably too fringe to matter in most contexts, but wouldn't your function return 111st for the year 11,092?
It would, indeed. Thanks for pointing out. Now I have fixed it and added a new test case.
OLD SOLUTION (Line 7)
UPDATED SOLUTION (Line 7)