Challenge
Write a function that will return an inputted numerical year in century format. The output should have the appropriate written ending ('...
For further actions, you may consider blocking this person and/or reporting abuse
A reasonably short and reasonably Rusty solution:
Garna robota!
Good job!
Diakuyu :)
Thanks :)
A bit of functional JS
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)
F#
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.
This would've been even more interesting using the strict usage of "century" ;-)
First handle the exceptions (i.e. 11 - 13), then just use the last digit to decide.
python
A length Javascript solution, but I did not want to divide by 100.
Tried it with a few different years including the edge cases.
Rust:
Insert Go Pun Here
century.go
century_test.go
Ah, this one was tricker than I thought because of the edge cases.
I choose a solution in JS that lists out all the endings in an object - but since they are almost all the same, maybe I should have done something else :)
Also, since I've started recording me solving these, you can check it out here: youtube.com/watch?v=ozws2mzhqkM
It's fixed now (I think). It should also support BC centuries.
I used your answer as a cheatsheet of sorts. Good job! :)
Oh, good catch
2000 must 20th century
Link: en.wikipedia.org/wiki/20th_century
Thanks