Skip to content

Commit 773cac0

Browse files
committed
finsh quiz2
1 parent b82fe79 commit 773cac0

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

exercises/quiz2.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,32 @@ mod my_module {
3232
use super::Command;
3333

3434
// TODO: Complete the function signature!
35-
pub fn transformer(input: ???) -> ??? {
35+
pub fn transformer(input: Vec<(String,Command)>) -> Vec<String> {
3636
// TODO: Complete the output declaration!
37-
let mut output: ??? = vec![];
37+
let mut output: Vec<String> = vec![];
3838
for (string, command) in input.iter() {
3939
// TODO: Complete the function body. You can do it!
40-
}
41-
output
40+
let result = match command {
41+
Command::Uppercase => string.to_uppercase(),
42+
Command::Trim => string.trim().to_string(),
43+
Command::Append(n) => {
44+
let mut result = string.clone();
45+
for _ in 0..*n {
46+
result.push_str("bar");
47+
}
48+
result
49+
}
50+
};
51+
output.push(result)
4252
}
53+
output
54+
}
4355
}
4456

4557
#[cfg(test)]
4658
mod tests {
4759
// TODO: What do we need to import to have `transformer` in scope?
48-
use ???;
60+
use super::my_module::transformer;
4961
use super::Command;
5062

5163
#[test]

0 commit comments

Comments
 (0)