Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
baiyazi233 committed Apr 8, 2024
1 parent cbe8c7c commit d947bcd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions exercises/iterators/iterators2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Execute `rustlings hint iterators2` or use the `hint` watch subcommand for a
// hint.

// I AM NOT DONE


// Step 1.
// Complete the `capitalize_first` function.
Expand All @@ -15,7 +15,12 @@ pub fn capitalize_first(input: &str) -> String {
let mut c = input.chars();
match c.next() {
None => String::new(),
Some(first) => ???,
Some(first) => {
let mut result = String::new();
result.push(first.to_uppercase().next().unwrap());
result.push_str(c.as_str());
result
}
}
}

Expand All @@ -24,15 +29,16 @@ 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::<Vec<_>>().join("")

}

#[cfg(test)]
Expand Down

0 comments on commit d947bcd

Please sign in to comment.