control flow, primitive types and vectors
This commit is contained in:
@@ -4,10 +4,13 @@ fn bigger(a: i32, b: i32) -> i32 {
|
||||
// Do not use:
|
||||
// - another function call
|
||||
// - additional variables
|
||||
|
||||
if a > b { a } else { b }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// You can optionally experiment here.
|
||||
println!("{}", bigger(32, 42));
|
||||
}
|
||||
|
||||
// Don't mind this for now :)
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
fn picky_eater(food: &str) -> &str {
|
||||
if food == "strawberry" {
|
||||
"Yummy!"
|
||||
} else if food == "potato" {
|
||||
"I guess I can eat that."
|
||||
} else {
|
||||
1
|
||||
"No thanks!"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ fn animal_habitat(animal: &str) -> &str {
|
||||
let identifier = if animal == "crab" {
|
||||
1
|
||||
} else if animal == "gopher" {
|
||||
2.0
|
||||
2
|
||||
} else if animal == "snake" {
|
||||
3
|
||||
} else {
|
||||
"Unknown"
|
||||
0
|
||||
};
|
||||
|
||||
// Don't change the expression below!
|
||||
|
||||
Reference in New Issue
Block a user