diff --git a/exercises/quiz2.rs b/exercises/quiz2.rs index 5c42dae0..2ba13be2 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, @@ -30,12 +28,35 @@ 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! + let out_res = match command { + Command::Uppercase => { + let res = string.to_uppercase(); + output.push(res); + } + Command::Trim => { + let res = string.trim().to_string(); + output.push(res); + } + Command::Append(x) => { + let res = append_fn(string, *x); + output.push(res); + } + }; } + + fn append_fn(string: &str, count: usize) -> String { + let mut result = String::from(string); + for _ in 0..count { + result += "bar"; + } + result + } + output } } @@ -43,8 +64,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() { diff --git a/temp_11956_ThreadId1.exe b/temp_11956_ThreadId1.exe new file mode 100644 index 00000000..873ab963 Binary files /dev/null and b/temp_11956_ThreadId1.exe differ diff --git a/temp_12120_ThreadId1.exe b/temp_12120_ThreadId1.exe new file mode 100644 index 00000000..0b2e5b1d Binary files /dev/null and b/temp_12120_ThreadId1.exe differ