DEV Community

loading...

Discussion on: Daily Challenge #48 - Facebook Likes

Collapse
brightone profile image
Oleksii Filonenko

Rust:

pub fn likes(names: &[&str]) -> String {
    match names {
        [] => String::from("no one likes this"),
        [a] => format!("{} likes this", a),
        [a, b] => format!("{} and {} like this", a, b),
        [a, b, c] => format!("{}, {} and {} like this", a, b, c),
        [a, b, ..] => format!("{}, {} and {} others like this", a, b, names.len() - 2),
    }
}