diff --git a/exercises/quiz2.rs b/exercises/quiz2.rs index d8fa954a..b7021442 100644 --- a/exercises/quiz2.rs +++ b/exercises/quiz2.rs @@ -18,7 +18,7 @@ // - The output element is going to be a Vector of strings. // Execute `rustlings hint quiz2` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE + pub enum Command { Uppercase, @@ -30,11 +30,25 @@ mod my_module { use super::Command; // TODO: Complete the function signature! - pub fn transformer(input: ???) -> ??? { + pub fn transformer(input: Vec<(String,Command)>) -> Vec { // TODO: Complete the output declaration! - let mut output: ??? = vec![]; + let mut output: Vec = vec![]; for (string, command) in input.iter() { // TODO: Complete the function body. You can do it! + match command{ + Command::Uppercase => { + let transformed_string = string.to_uppercase(); + output.push(transformed_string); + } + Command::Trim =>{ + let transformed_string = string.trim().to_string(); + output.push(transformed_string); + } + Command::Append(count) => { + let appended_string = string.clone() + &"bar".repeat(*count); + output.push(appended_string); + } + } } output } @@ -43,7 +57,7 @@ mod my_module { #[cfg(test)] mod tests { // TODO: What do we have to import to have `transformer` in scope? - use ???; + use super::my_module::transformer; use super::Command; #[test]