diff --git a/Rust/rustifinity/challenges/closures.rs b/Rust/rustifinity/challenges/closures.rs new file mode 100644 index 0000000..e2b4356 --- /dev/null +++ b/Rust/rustifinity/challenges/closures.rs @@ -0,0 +1,19 @@ +pub fn create_closures() -> ( + impl Fn(i32, i32) -> i32, + impl Fn(i32, i32) -> i32, + impl Fn(i32, i32) -> i32, +) { + let add_closure = |a, b| { + // Step 1: Implement here + a + b + }; + + // Step 2: + // Create the `subtract_closure` closure that subtracts two `i32` values. + let subtract_closure = |a, b| a - b; + // Step 3: + // Create the `multiply_closure` closure that multiplies two `i32` values. + let multiply_closure = |a, b| a * b; + + (add_closure, subtract_closure, multiply_closure) +} diff --git a/Rust/rustifinity/challenges/control-flow.rs b/Rust/rustifinity/challenges/control-flow.rs new file mode 100644 index 0000000..4d7c507 --- /dev/null +++ b/Rust/rustifinity/challenges/control-flow.rs @@ -0,0 +1,12 @@ +pub fn check_number_sign(number: i32) -> String { + // Return `"positive"` if the number is positive. + // Return `"negative"` if the number is negative. + // Return `"zero"` if the number is zero. + if number > 0 { + String::from("positive") + } else if number < 0 { + String::from("negative") + } else { + String::from("zero") + } +}