Skip to content

Commit f56e7cf

Browse files
committed
solve quiz2
1 parent 177716d commit f56e7cf

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

exercises/quiz2.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
// - The output element is going to be a Vector of strings.
2020
//
2121
// No hints this time!
22-
2322
// I AM NOT DONE
2423

2524
pub enum Command {
@@ -32,11 +31,24 @@ mod my_module {
3231
use super::Command;
3332

3433
// TODO: Complete the function signature!
35-
pub fn transformer(input: ???) -> ??? {
34+
pub fn transformer(input: Vec<(String, Command)>) -> Vec<String> {
3635
// TODO: Complete the output declaration!
37-
let mut output: ??? = vec![];
36+
let mut output: Vec<String> = vec![];
3837
for (string, command) in input.iter() {
3938
// TODO: Complete the function body. You can do it!
39+
match command {
40+
Command::Uppercase => output.push(string.to_uppercase()),
41+
Command::Trim => output.push(string.trim().to_string()),
42+
Command::Append(num) => {
43+
let mut append = String::new();
44+
let mut n: usize = 0;
45+
while n < *num {
46+
append.push_str("bar");
47+
n += 1;
48+
}
49+
output.push(string .to_owned()+ &append);
50+
},
51+
}
4052
}
4153
output
4254
}
@@ -45,7 +57,7 @@ mod my_module {
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)