Skip to content

Commit 9df8e00

Browse files
add closure and control-flow
1 parent 4cf0288 commit 9df8e00

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pub fn create_closures() -> (
2+
impl Fn(i32, i32) -> i32,
3+
impl Fn(i32, i32) -> i32,
4+
impl Fn(i32, i32) -> i32,
5+
) {
6+
let add_closure = |a, b| {
7+
// Step 1: Implement here
8+
a + b
9+
};
10+
11+
// Step 2:
12+
// Create the `subtract_closure` closure that subtracts two `i32` values.
13+
let subtract_closure = |a, b| a - b;
14+
// Step 3:
15+
// Create the `multiply_closure` closure that multiplies two `i32` values.
16+
let multiply_closure = |a, b| a * b;
17+
18+
(add_closure, subtract_closure, multiply_closure)
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pub fn check_number_sign(number: i32) -> String {
2+
// Return `"positive"` if the number is positive.
3+
// Return `"negative"` if the number is negative.
4+
// Return `"zero"` if the number is zero.
5+
if number > 0 {
6+
String::from("positive")
7+
} else if number < 0 {
8+
String::from("negative")
9+
} else {
10+
String::from("zero")
11+
}
12+
}

0 commit comments

Comments
 (0)