mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-13 21:03:31 +02:00
feat: progress iterators
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user