DEV Community

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

Collapse
 
olekria profile image
Olek Ria • Edited

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)