From 4f57728dd9b19ff73c513fbbbe28ee2392333e8f Mon Sep 17 00:00:00 2001 From: perro Date: Wed, 22 Feb 2023 11:35:08 -0800 Subject: [PATCH] Quiz 2 --- exercises/quiz2.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/exercises/quiz2.rs b/exercises/quiz2.rs index 5c42dae..4b659a1 100644 --- a/exercises/quiz2.rs +++ b/exercises/quiz2.rs @@ -18,8 +18,6 @@ // - The output element is going to be a Vector of strings. // No hints this time! -// I AM NOT DONE - pub enum Command { Uppercase, Trim, @@ -29,12 +27,14 @@ pub enum Command { mod my_module { use super::Command; - // TODO: Complete the function signature! - pub fn transformer(input: ???) -> ??? { - // TODO: Complete the output declaration! - let mut output: ??? = vec![]; + pub fn transformer(input: Vec<(String, Command)>) -> Vec { + let mut output: Vec = vec![]; for (string, command) in input.iter() { - // TODO: Complete the function body. You can do it! + output.push(match command { + Command::Uppercase => string.to_uppercase(), + Command::Trim => string.trim().to_string(), + Command::Append(times) => format!("{}{}", string, "bar".repeat(*times)), + }) } output } @@ -42,8 +42,7 @@ mod my_module { #[cfg(test)] mod tests { - // TODO: What do we need to import to have `transformer` in scope? - use ???; + use super::my_module::transformer; use super::Command; #[test]