wip
This commit is contained in:
@@ -6,17 +6,18 @@
|
||||
// Execute `rustlings hint iterators2` or use the `hint` watch subcommand for a
|
||||
// hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
// Step 1.
|
||||
// Complete the `capitalize_first` function.
|
||||
// "hello" -> "Hello"
|
||||
pub fn capitalize_first(input: &str) -> String {
|
||||
let mut c = input.chars();
|
||||
match c.next() {
|
||||
let cap = match c.next() {
|
||||
None => String::new(),
|
||||
Some(first) => ???,
|
||||
}
|
||||
Some(first) => first.to_uppercase().to_string(),
|
||||
};
|
||||
let rest: String = c.collect();
|
||||
|
||||
format!("{cap}{rest}")
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
@@ -24,7 +25,7 @@ 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(|f| capitalize_first(f)).collect()
|
||||
}
|
||||
|
||||
// Step 3.
|
||||
@@ -32,7 +33,7 @@ pub fn capitalize_words_vector(words: &[&str]) -> Vec<String> {
|
||||
// Return a single string.
|
||||
// ["hello", " ", "world"] -> "Hello World"
|
||||
pub fn capitalize_words_string(words: &[&str]) -> String {
|
||||
String::new()
|
||||
words.iter().map(|f| capitalize_first(f)).collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user