Complete quiz 2

This commit is contained in:
Suzie Kim 2024-02-01 15:40:18 -05:00
parent 6f2ce95f6e
commit ec6bd80f6a
No known key found for this signature in database
GPG key ID: 83C4CC3808F9AAE9

View file

@ -20,8 +20,6 @@
//
// No hints this time!
// I AM NOT DONE
pub enum Command {
Uppercase,
Trim,
@ -32,11 +30,24 @@ mod my_module {
use super::Command;
// TODO: Complete the function signature!
pub fn transformer(input: ???) -> ??? {
pub fn transformer(input: Vec<(String, Command)>) -> Vec<String> {
// TODO: Complete the output declaration!
let mut output: ??? = vec![];
let mut output: Vec<String> = vec![];
for (string, command) in input.iter() {
// TODO: Complete the function body. You can do it!
match command {
Command::Uppercase => output.push(string.to_uppercase()),
Command::Trim => output.push(string.trim().to_string()),
Command::Append(count) => {
let mut new_string = string.clone();
// The star in front of count dereferences the value of count.
// This is necessary because the append method expects a usize, not a &usize.
for _ in 0..*count {
new_string.push_str("bar");
}
output.push(new_string)
}
}
}
output
}
@ -45,7 +56,7 @@ mod my_module {
#[cfg(test)]
mod tests {
// TODO: What do we need to import to have `transformer` in scope?
use ???;
use crate::my_module::transformer;
use super::Command;
#[test]