mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 13:19:18 +00:00
[Add] exercises/quiz2.rs
This commit is contained in:
parent
4faeeb807c
commit
e9ac767f49
@ -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,
|
||||
@ -29,12 +27,25 @@ pub enum Command {
|
||||
mod my_module {
|
||||
use super::Command;
|
||||
|
||||
// TODO: Complete the function signature!
|
||||
pub fn transformer(input: ???) -> ??? {
|
||||
// TODO: Complete the output declaration!
|
||||
let mut output: ??? = vec![];
|
||||
pub fn transformer(input: Vec<(String, Command)>) -> Vec<String> {
|
||||
let mut output: Vec<String> = vec![];
|
||||
|
||||
for (string, command) in input.iter() {
|
||||
// TODO: Complete the function body. You can do it!
|
||||
let result = match command {
|
||||
Command::Uppercase => string.to_uppercase(),
|
||||
Command::Trim => string.trim().to_owned(),
|
||||
Command::Append(count) => {
|
||||
let mut string = string.clone();
|
||||
|
||||
for _ in 0..*count {
|
||||
string.push_str("bar");
|
||||
}
|
||||
|
||||
string
|
||||
},
|
||||
};
|
||||
|
||||
output.push(result);
|
||||
}
|
||||
output
|
||||
}
|
||||
@ -42,8 +53,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]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user