From 179bc4ad68bff7e27a9fb906653b547bba45aa65 Mon Sep 17 00:00:00 2001 From: asif256000 Date: Thu, 12 Jan 2023 20:17:51 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=F0=9F=A6=80=20Quiz=20Solved?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exercises/quiz2.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/exercises/quiz2.rs b/exercises/quiz2.rs index 606d3c70..a4141f33 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, @@ -27,14 +25,21 @@ pub enum Command { } mod my_module { + // use std::marker::Tuple; + 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 => output.push(string.to_uppercase()), + Command::Trim => output.push(string.trim().to_string()), + Command::Append(x) => output.push(string.to_owned() + &"bar".repeat(*x)), + } } output } @@ -43,8 +48,8 @@ mod my_module { #[cfg(test)] mod tests { // TODO: What do we have to import to have `transformer` in scope? - use ???; use super::Command; + use my_module::transformer; #[test] fn it_works() {