This commit is contained in:
liruifengv 2022-11-03 14:11:43 +08:00
parent 54b3be8264
commit 35f9c20299

View File

@ -18,7 +18,6 @@
// - The output element is going to be a Vector of strings. // - The output element is going to be a Vector of strings.
// No hints this time! // No hints this time!
// I AM NOT DONE
pub enum Command { pub enum Command {
Uppercase, Uppercase,
Trim, Trim,
@ -29,26 +28,13 @@ mod my_module {
use super::Command; use super::Command;
pub fn transformer(input: Vec<(String, Command)>) -> Vec<String> { pub fn transformer(input: Vec<(String, Command)>) -> Vec<String> {
let mut output: Vec<String> = vec![]; input.iter().map(|(content, command)| {
for (string, command) in input.iter() {
match command { match command {
Command::Uppercase => { Command::Uppercase => content.to_uppercase(),
let str = String::from(string).to_uppercase(); Command::Trim => content.trim().to_string(),
output.push(str) Command::Append(n) => format!("{}{}", content, "bar".repeat(*n))
},
Command::Trim => {
let str = String::from(string).trim().into();
output.push(str)
},
Command::Append(_n) => {
let mut str = String::from(string);
let a = "bar".repeat(*_n);
str.push_str(a.as_str());
output.push(str)
},
} }
} }).collect()
output
} }
} }