defmoduleYeardo@doc"""
Returns the stringified, suffixed form of a numeric year.
Use `to_century/1` if you need to do further numeric work on the
century number before (or in lieu of) using it as a string.
## Examples
iex> Year.centurify(8120)
"82nd"
iex> Year.centurify(30200)
"303rd"
iex> Year.centurify(1601)
"17th"
iex> Year.centurify(2020)
"21st"
iex> Year.centurify(3030)
"31st"
iex> Year.centurify(1900)
"20th"
iex> Year.centurify(1776)
"18th"
"""defcenturify(year)docentury=to_century(year)"#{century}#{suffix(century)}"enddefto_century(year),do:div(year,100)+1defpsuffix(number)whennumber>=100,do:number|>rem(100)|>suffixdefpsuffix(number)whennumberin11..13,do:"th"defpsuffix(number)docaserem(number,10)do1->"st"2->"nd"3->"rd"_->"th"endendenddefmoduleYearTestdoimportExUnit.CasedoctestYearend
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