This commit is contained in:
liruifengv 2022-11-03 10:58:46 +08:00
parent 8c2d3b590e
commit 54b3be8264
2 changed files with 28 additions and 11 deletions

View File

@ -10,10 +10,16 @@
// Write a function that calculates the price of an order of apples given // Write a function that calculates the price of an order of apples given
// the quantity bought. No hints this time! // the quantity bought. No hints this time!
// I AM NOT DONE
// Put your function here! // Put your function here!
// fn calculate_price_of_apples { fn calculate_price_of_apples(num: i32) -> i32 {
let mut price = 0;
if num <= 40 {
price = num * 2;
} else {
price = num * 1;
}
price
}
// Don't modify this function! // Don't modify this function!
#[test] #[test]

View File

@ -19,7 +19,6 @@
// No hints this time! // No hints this time!
// I AM NOT DONE // I AM NOT DONE
pub enum Command { pub enum Command {
Uppercase, Uppercase,
Trim, Trim,
@ -29,12 +28,25 @@ pub enum Command {
mod my_module { mod my_module {
use super::Command; use super::Command;
// TODO: Complete the function signature! pub fn transformer(input: Vec<(String, Command)>) -> Vec<String> {
pub fn transformer(input: ???) -> ??? { let mut output: Vec<String> = vec![];
// TODO: Complete the output declaration!
let mut output: ??? = vec![];
for (string, command) in input.iter() { for (string, command) in input.iter() {
// TODO: Complete the function body. You can do it! match command {
Command::Uppercase => {
let str = String::from(string).to_uppercase();
output.push(str)
},
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)
},
}
} }
output output
} }
@ -42,8 +54,7 @@ mod my_module {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
// TODO: What do we have to import to have `transformer` in scope? use super::my_module::transformer;
use ???;
use super::Command; use super::Command;
#[test] #[test]