loading...

re: Daily Challenge #190 - capitalizeFirstLast VIEW POST

FULL DISCUSSION
 

Rust Solution:

fn capital_first_last(sentence: &str) -> String {
    sentence.split_whitespace()
        .map(|word| first_last(word))
        .collect::<Vec<String>>()
        .join(" ")
}

fn first_last(word: &str) -> String {
    let chars: Vec<char> = word.chars().collect();
    chars[0].to_uppercase().nth(0).unwrap().to_string() +
        &chars[1..chars.len()-1].into_iter().collect::<String>() + 
        &chars.last().unwrap().to_uppercase().nth(0).unwrap().to_string()
}
Code of Conduct Report abuse