mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-12 21:59:18 +00:00
quiz2
This commit is contained in:
parent
54b3be8264
commit
35f9c20299
@ -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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user