mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-05 10:19:18 +00:00
Fix capitalization in iterators2.rs
This commit is contained in:
parent
2c4dc73771
commit
9247e98c37
@ -6,8 +6,6 @@
|
|||||||
// Execute `rustlings hint iterators2` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint iterators2` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
// Step 1.
|
// Step 1.
|
||||||
// Complete the `capitalize_first` function.
|
// Complete the `capitalize_first` function.
|
||||||
// "hello" -> "Hello"
|
// "hello" -> "Hello"
|
||||||
@ -15,7 +13,7 @@ pub fn capitalize_first(input: &str) -> String {
|
|||||||
let mut c = input.chars();
|
let mut c = input.chars();
|
||||||
match c.next() {
|
match c.next() {
|
||||||
None => String::new(),
|
None => String::new(),
|
||||||
Some(first) => ???,
|
Some(first) => first.to_string().to_uppercase() + &input[1..],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +22,12 @@ pub fn capitalize_first(input: &str) -> String {
|
|||||||
// Return a vector of strings.
|
// Return a vector of strings.
|
||||||
// ["hello", "world"] -> ["Hello", "World"]
|
// ["hello", "world"] -> ["Hello", "World"]
|
||||||
pub fn capitalize_words_vector(words: &[&str]) -> Vec<String> {
|
pub fn capitalize_words_vector(words: &[&str]) -> Vec<String> {
|
||||||
vec![]
|
let mut new_vec: Vec<String> = vec![];
|
||||||
|
for word in words.iter() {
|
||||||
|
new_vec.push(capitalize_first(word))
|
||||||
|
}
|
||||||
|
|
||||||
|
new_vec
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3.
|
// Step 3.
|
||||||
@ -32,7 +35,12 @@ pub fn capitalize_words_vector(words: &[&str]) -> Vec<String> {
|
|||||||
// Return a single string.
|
// Return a single string.
|
||||||
// ["hello", " ", "world"] -> "Hello World"
|
// ["hello", " ", "world"] -> "Hello World"
|
||||||
pub fn capitalize_words_string(words: &[&str]) -> String {
|
pub fn capitalize_words_string(words: &[&str]) -> String {
|
||||||
String::new()
|
let mut new_string = String::new();
|
||||||
|
for word in words.iter() {
|
||||||
|
new_string.push_str(&capitalize_first(word))
|
||||||
|
}
|
||||||
|
|
||||||
|
new_string
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user