summaryrefslogtreecommitdiff
path: root/exercises
diff options
context:
space:
mode:
authorapogeeoak <59737221+apogeeoak@users.noreply.github.com>2021-02-11 21:24:32 -0500
committerapogeeoak <59737221+apogeeoak@users.noreply.github.com>2021-02-11 21:24:32 -0500
commitbaf4ba175ba6eb92989e3dd54ecbec4bedc9a863 (patch)
treeb57c3e74e799a514e3d052bb654aed57eec04063 /exercises
parentab57c26cf9199eca7937a75712079d908e5d330d (diff)
fix(iterators2): Moved errors out of tests.
Closes #359
Diffstat (limited to 'exercises')
-rw-r--r--exercises/standard_library_types/iterators2.rs38
1 files changed, 24 insertions, 14 deletions
diff --git a/exercises/standard_library_types/iterators2.rs b/exercises/standard_library_types/iterators2.rs
index 84d14ae..87b4eaa 100644
--- a/exercises/standard_library_types/iterators2.rs
+++ b/exercises/standard_library_types/iterators2.rs
@@ -1,28 +1,41 @@
// iterators2.rs
-// In this module, you'll learn some of the unique advantages that iterators can offer.
-// Step 1. Complete the `capitalize_first` function to pass the first two cases.
-// Step 2. Apply the `capitalize_first` function to a vector of strings.
-// Ensure that it returns a vector of strings as well.
-// Step 3. Apply the `capitalize_first` function again to a list.
-// Try to ensure it returns a single string.
+// In this exercise, you'll learn some of the unique advantages that iterators
+// can offer. Follow the steps to complete the exercise.
// As always, there are hints if you execute `rustlings hint iterators2`!
// 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() {
None => String::new(),
- Some(first) => first.collect::<String>() + c.as_str(),
+ Some(first) => ???,
}
}
+// Step 2.
+// Apply the `capitalize_first` function to a slice of string slices.
+// Return a vector of strings.
+// ["hello", "world"] -> ["Hello", "World"]
+pub fn capitalize_words_vector(words: &[&str]) -> Vec<String> {
+ vec![]
+}
+
+// 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()
+}
+
#[cfg(test)]
mod tests {
use super::*;
- // Step 1.
- // Tests that verify your `capitalize_first` function implementation
#[test]
fn test_success() {
assert_eq!(capitalize_first("hello"), "Hello");
@@ -33,18 +46,15 @@ mod tests {
assert_eq!(capitalize_first(""), "");
}
- // Step 2.
#[test]
fn test_iterate_string_vec() {
let words = vec!["hello", "world"];
- let capitalized_words: Vec<String> = // TODO
- assert_eq!(capitalized_words, ["Hello", "World"]);
+ assert_eq!(capitalize_words_vector(&words), ["Hello", "World"]);
}
#[test]
fn test_iterate_into_string() {
let words = vec!["hello", " ", "world"];
- let capitalized_words = // TODO
- assert_eq!(capitalized_words, "Hello World");
+ assert_eq!(capitalize_words_string(&words), "Hello World");
}
}