From 7b6ebb8654ea25933e50420282d188a7feac4d0b Mon Sep 17 00:00:00 2001 From: Rock070 Date: Sun, 5 May 2024 17:24:14 +0800 Subject: [PATCH] Complete quiz2 --- exercises/quiz2.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/exercises/quiz2.rs b/exercises/quiz2.rs index 29925caf..ee2ee994 100644 --- a/exercises/quiz2.rs +++ b/exercises/quiz2.rs @@ -32,10 +32,15 @@ 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() { + match command { + Command::Uppercase => output.push(string.to_uppercase()), + Command::Trim => output.push(string.trim().to_owned()), + Command::Append(n) => output.push(string.to_owned() + &("bar".repeat(*n))), + } // TODO: Complete the function body. You can do it! } output @@ -45,7 +50,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]