From 8859a5b72400892c4e9b86c6f2a9fcb7b3a1c3b2 Mon Sep 17 00:00:00 2001 From: Robert Zhao Date: Fri, 9 Jun 2023 19:40:04 -0400 Subject: [PATCH] Complete quiz2 --- exercises/quiz2.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/exercises/quiz2.rs b/exercises/quiz2.rs index 5c42dae0..4c392c9c 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,17 @@ 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::from(string.to_uppercase()), + Command::Trim => String::from(string.trim()), + Command::Append(times) => { + let bars = "bar".repeat(*times); + format!("{string}{bars}") + } + }); } output } @@ -42,9 +45,8 @@ mod my_module { #[cfg(test)] mod tests { - // TODO: What do we need to import to have `transformer` in scope? - use ???; use super::Command; + use crate::my_module::transformer; #[test] fn it_works() {