Skip to content

Commit 93d62f0

Browse files
add if-else, countdown and sum of evens
1 parent 9df8e00 commit 93d62f0

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pub fn countdown(n: u32) -> Vec<u32> {
2+
// TODO: Implement the countdown using a while loop
3+
if n == 0 {
4+
vec![0]
5+
} else {
6+
let mut vect : Vec<u32> = Vec::new();
7+
let mut m = n;
8+
while m > 0 {
9+
vect.push(m);
10+
m -= 1;
11+
}
12+
vect.push(0);
13+
vect
14+
}
15+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pub fn is_even(n: i32) -> bool {
2+
// Your code here...
3+
if n % 2 == 0 {
4+
true
5+
} else {
6+
false
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pub fn sum_of_evens(start: i32, end: i32) -> i32 {
2+
let mut sum = 0;
3+
for num in start..=end + 1 {
4+
if num % 2 == 0 {
5+
sum += num;
6+
}
7+
}
8+
sum
9+
}

0 commit comments

Comments
 (0)