diff options
| author | Hunter Kvalevog <hunter@kvog.sh> | 2026-09-27 17:28:34 -0500 |
|---|---|---|
| committer | Hunter Kvalevog <hunter@kvog.sh> | 2026-09-27 17:28:34 -0500 |
| commit | 67fb6c0eb507965836201551f90c7d637bf6cee0 (patch) | |
| tree | 59e405f7f98a0451d3a9051c2e2ed03dc3585dfa /rustlings/exercises/18_iterators/iterators2.rs | |
| parent | 54731f0fc0b0fde18438853c0a8abaa968edb57a (diff) | |
rustlings: complete 18
Diffstat (limited to 'rustlings/exercises/18_iterators/iterators2.rs')
| -rw-r--r-- | rustlings/exercises/18_iterators/iterators2.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/rustlings/exercises/18_iterators/iterators2.rs b/rustlings/exercises/18_iterators/iterators2.rs index 5903e65..c827529 100644 --- a/rustlings/exercises/18_iterators/iterators2.rs +++ b/rustlings/exercises/18_iterators/iterators2.rs @@ -7,7 +7,7 @@ fn capitalize_first(input: &str) -> String { let mut chars = input.chars(); match chars.next() { None => String::new(), - Some(first) => todo!(), + Some(first) => first.to_uppercase().to_string() + &input[1..], } } @@ -15,14 +15,20 @@ fn capitalize_first(input: &str) -> String { // Return a vector of strings. // ["hello", "world"] -> ["Hello", "World"] fn capitalize_words_vector(words: &[&str]) -> Vec<String> { - // ??? + let mut v = Vec::new(); + for word in words { + if !word.trim().is_empty() { + v.push(capitalize_first(word)); + } + } + v } // TODO: Apply the `capitalize_first` function again to a slice of string // slices. Return a single string. // ["hello", " ", "world"] -> "Hello World" fn capitalize_words_string(words: &[&str]) -> String { - // ??? + capitalize_words_vector(words).join(" ") } fn main() { |