From 89d303737e3fc7fd3613a8651a8085f5aafc4a5b Mon Sep 17 00:00:00 2001 From: perro Date: Thu, 2 Mar 2023 10:11:25 -0800 Subject: [PATCH] Ejercicios 72/94 --- exercises/iterators/iterators2.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/exercises/iterators/iterators2.rs b/exercises/iterators/iterators2.rs index 464630a..afade9d 100644 --- a/exercises/iterators/iterators2.rs +++ b/exercises/iterators/iterators2.rs @@ -3,8 +3,6 @@ // can offer. Follow the steps to complete the exercise. // Execute `rustlings hint iterators2` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE - // Step 1. // Complete the `capitalize_first` function. // "hello" -> "Hello" @@ -21,7 +19,11 @@ 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![] + let mut replaced = vec![]; + for word in words.iter() { + replaced.push(capitalize_first(word)); + } + replaced } // Step 3. @@ -29,7 +31,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() + capitalize_words_vector(words).join("") } #[cfg(test)]