diff --git a/exercises/quiz1.rs b/exercises/quiz1.rs index dbb5cdc9..19f018e9 100644 --- a/exercises/quiz1.rs +++ b/exercises/quiz1.rs @@ -10,10 +10,16 @@ // Write a function that calculates the price of an order of apples given // the quantity bought. No hints this time! -// I AM NOT DONE - // 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! #[test] diff --git a/exercises/quiz2.rs b/exercises/quiz2.rs index 606d3c70..0863020d 100644 --- a/exercises/quiz2.rs +++ b/exercises/quiz2.rs @@ -19,7 +19,6 @@ // No hints this time! // I AM NOT DONE - pub enum Command { Uppercase, Trim, @@ -29,12 +28,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 { + let mut output: Vec = vec![]; 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 } @@ -42,8 +54,7 @@ mod my_module { #[cfg(test)] mod tests { - // TODO: What do we have to import to have `transformer` in scope? - use ???; + use super::my_module::transformer; use super::Command; #[test]