feat: progress iterators

This commit is contained in:
2026-09-13 18:23:25 +02:00
parent 88b981b50c
commit 50f23f7e48
3 changed files with 20 additions and 4 deletions
+5 -1
View File
@@ -1,13 +1,15 @@
// In this exercise, you'll learn some of the unique advantages that iterators
// can offer.
// I failed.
// TODO: Complete the `capitalize_first` function.
// "hello" -> "Hello"
fn capitalize_first(input: &str) -> String {
let mut chars = input.chars();
match chars.next() {
None => String::new(),
Some(first) => char::to_uppercase(first).to_string(),
Some(first) => first.to_uppercase().to_string() + chars.as_str(),
}
}
@@ -16,6 +18,7 @@ fn capitalize_first(input: &str) -> String {
// ["hello", "world"] -> ["Hello", "World"]
fn capitalize_words_vector(words: &[&str]) -> Vec<String> {
// ???
words.iter().map(|word| capitalize_first(word)).collect()
}
// TODO: Apply the `capitalize_first` function again to a slice of string
@@ -23,6 +26,7 @@ fn capitalize_words_vector(words: &[&str]) -> Vec<String> {
// ["hello", " ", "world"] -> "Hello World"
fn capitalize_words_string(words: &[&str]) -> String {
// ???
words.iter().map(|word| capitalize_first(word)).collect()
}
fn main() {