From 3f97251b6ef36f4b45d9a373d0b5a8ee2db7f9ef Mon Sep 17 00:00:00 2001 From: Nielsen Date: Wed, 3 Jan 2024 11:31:58 +0100 Subject: [PATCH] Update quiz2.rs --- exercises/quiz2.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/exercises/quiz2.rs b/exercises/quiz2.rs index 29925caf..3a2fc09a 100644 --- a/exercises/quiz2.rs +++ b/exercises/quiz2.rs @@ -20,8 +20,6 @@ // // No hints this time! -// I AM NOT DONE - pub enum Command { Uppercase, Trim, @@ -32,11 +30,16 @@ 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 => output.push(string.to_string().to_uppercase()), + Command::Trim => output.push(string.trim().to_string()), + Command::Append(usize) => output.push(string.to_owned() + &"bar".repeat(*usize)), + }; } output } @@ -45,7 +48,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::*; use super::Command; #[test]