Skip to content

Commit

Permalink
add closure and control-flow
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphonseMehounme committed Nov 29, 2024
1 parent 4cf0288 commit 9df8e00
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Rust/rustifinity/challenges/closures.rs
Original file line number Diff line number Diff line change
@@ -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)
}
12 changes: 12 additions & 0 deletions Rust/rustifinity/challenges/control-flow.rs
Original file line number Diff line number Diff line change
@@ -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")
}
}

0 comments on commit 9df8e00

Please sign in to comment.