DEV Community

loading...

Discussion on: Daily Challenge #54 - What century is it?

Collapse
olekria profile image
Olek Ria

F#

let whatCenture (year: int) =
    let centure = year / 100 + 1

    let suffix x =
        if (centure % 13) = 12  || (centure % 13) = 11
        then "th"
        else match x % 10 with 
                | 1 -> "st"
                | 2 -> "nd"
                | 3 -> "rd"
                | _ -> "th"

    (string centure) + (suffix centure)

Collapse
citizen428 profile image
Michael Kohl

Always nice to see another F# solution :-)

Collapse
olekria profile image