Skip to content

Commit

Permalink
finish iterators2
Browse files Browse the repository at this point in the history
  • Loading branch information
cyz-ing committed Jan 24, 2025
1 parent f549ed5 commit 24db205
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions exercises/iterators/iterators2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}

Expand All @@ -24,15 +26,15 @@ pub fn capitalize_first(input: &str) -> String {
// Return a vector of strings.
// ["hello", "world"] -> ["Hello", "World"]
pub fn capitalize_words_vector(words: &[&str]) -> Vec<String> {
vec![]
words.iter().map(|word| capitalize_first(word)).collect()
}

// Step 3.
// Apply the `capitalize_first` function again to a slice of string slices.
// 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)]
Expand Down

0 comments on commit 24db205

Please sign in to comment.