DEV Community

loading...

Discussion on: Daily Challenge #39 - Virus

Collapse
jay profile image
Jay

Rust Solution: Playground

fn solver(sentance: &str) -> String {
    sentance
        .to_ascii_lowercase()
        .replace("ie", "ei")
        .split_whitespace()
        .enumerate()
        .map(|(i, word)| {
            if i == 0 {
                let mut ch = word.chars();
                match ch.next() {
                    None => String::new(),
                    Some(c) => c.to_uppercase().chain(ch).collect(),
                }
            } else {
                word.to_string()
            }
        })
        .collect::<Vec<String>>()
        .join(" ")
}