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)
const suffix = Math.floor(cent / 10) === 1 ? 'th'
UPDATED SOLUTION (Line 7)
const suffix = Math.floor(cent / 10) % 10 === 1 ? 'th'
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)