From 1567306a6c815b9b4a44de8d838e740978acbef7 Mon Sep 17 00:00:00 2001 From: Michael Cain Date: Sat, 25 Feb 2023 16:00:52 -0600 Subject: [PATCH] solutions --- exercises/if/if1.rs | 7 +++++-- exercises/if/if2.rs | 10 ++++------ exercises/quiz1.rs | 10 +++++++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/exercises/if/if1.rs b/exercises/if/if1.rs index 587e03f8..0507ac0e 100644 --- a/exercises/if/if1.rs +++ b/exercises/if/if1.rs @@ -1,13 +1,16 @@ // if1.rs // Execute `rustlings hint if1` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE - pub fn bigger(a: i32, b: i32) -> i32 { // Complete this function to return the bigger number! // Do not use: // - another function call // - additional variables + if a > b { + return a; + } else { + return b; + } } // Don't mind this for now :) diff --git a/exercises/if/if2.rs b/exercises/if/if2.rs index effddbb6..e4f0ccf0 100644 --- a/exercises/if/if2.rs +++ b/exercises/if/if2.rs @@ -4,13 +4,11 @@ // Step 2: Get the bar_for_fuzz and default_to_baz tests passing! // Execute `rustlings hint if2` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE - pub fn foo_if_fizz(fizzish: &str) -> &str { - if fizzish == "fizz" { - "foo" - } else { - 1 + match fizzish { + "fizz" => "foo", + "fuzz" => "bar", + _ => "baz", } } diff --git a/exercises/quiz1.rs b/exercises/quiz1.rs index dbb5cdc9..c8ae51ae 100644 --- a/exercises/quiz1.rs +++ b/exercises/quiz1.rs @@ -10,10 +10,14 @@ // 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(amount: u32) -> u32 { + if amount > 40 { + return amount * 1; + } else { + return amount * 2; + } +} // Don't modify this function! #[test]