From 24db2050a3041270bbe85429239a4b02a4c63f0d Mon Sep 17 00:00:00 2001 From: cyz-ing <1316769374@qq.com> Date: Fri, 24 Jan 2025 03:40:54 +0000 Subject: [PATCH] finish iterators2 --- exercises/iterators/iterators2.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/exercises/iterators/iterators2.rs b/exercises/iterators/iterators2.rs index dda82a08..bb5d70c6 100644 --- a/exercises/iterators/iterators2.rs +++ b/exercises/iterators/iterators2.rs @@ -15,7 +15,9 @@ pub fn capitalize_first(input: &str) -> String { let mut c = input.chars(); match c.next() { None => String::new(), - Some(first) => ???, + Some(first) => { + first.to_uppercase().to_string() + c.as_str() + } } } @@ -24,7 +26,7 @@ pub fn capitalize_first(input: &str) -> String { // Return a vector of strings. // ["hello", "world"] -> ["Hello", "World"] pub fn capitalize_words_vector(words: &[&str]) -> Vec { - vec![] + words.iter().map(|word| capitalize_first(word)).collect() } // Step 3. @@ -32,7 +34,7 @@ pub fn capitalize_words_vector(words: &[&str]) -> Vec { // Return a single string. // ["hello", " ", "world"] -> "Hello World" pub fn capitalize_words_string(words: &[&str]) -> String { - String::new() + words.iter().map(|word| capitalize_first(word)).collect() } #[cfg(test)]