loading...

re: Daily Challenge #54 - What century is it? VIEW POST

FULL DISCUSSION
 

Rust:

fn century_name(year: u32) -> String {
    let century = (year / 100) + 1;
    format!(
        "{}{}",
        century,
        match century % 10 {
            _ if century > 10 && century < 14 => "th", // teen numbers exception
            1 => "st",
            2 => "nd",
            3 => "rd",
            _ => "th",
        }
    )
}
Code of Conduct Report abuse