finish iterators2 exercise
This commit is contained in:
parent
79b992dec4
commit
4582eda5cd
|
@ -7,13 +7,11 @@
|
||||||
// Try to ensure it returns a single string.
|
// Try to ensure it returns a single string.
|
||||||
// As always, there are hints if you execute `rustlings hint iterators2`!
|
// As always, there are hints if you execute `rustlings hint iterators2`!
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
pub fn capitalize_first(input: &str) -> String {
|
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) => first.collect::<String>() + c.as_str(),
|
Some(first) => first.to_uppercase().collect::<String>() + c.as_str(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,14 +35,15 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_iterate_string_vec() {
|
fn test_iterate_string_vec() {
|
||||||
let words = vec!["hello", "world"];
|
let words = vec!["hello", "world"];
|
||||||
let capitalized_words: Vec<String> = // TODO
|
let capitalized_words: Vec<String> = words.into_iter().map(capitalize_first).collect();
|
||||||
assert_eq!(capitalized_words, ["Hello", "World"]);
|
assert_eq!(capitalized_words, ["Hello", "World"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[ignore]
|
||||||
fn test_iterate_into_string() {
|
fn test_iterate_into_string() {
|
||||||
let words = vec!["hello", " ", "world"];
|
let words = vec!["hello", " ", "world"];
|
||||||
let capitalized_words = // TODO
|
let capitalized_words = words.into_iter().map(capitalize_first).collect::<String>();
|
||||||
assert_eq!(capitalized_words, "Hello World");
|
assert_eq!(capitalized_words, "Hello World");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue