mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-21 21:42:23 -05:00
exercise for the ternary operator
i.e. if-then-else *expression* in Rust
This commit is contained in:
parent
dbad16021c
commit
802e6ac270
1 changed files with 51 additions and 0 deletions
51
ex6.rs
Normal file
51
ex6.rs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
fn bigger(a: i32, b:i32) -> i32 {
|
||||||
|
// Complete this function to return the bigger number!
|
||||||
|
// Do not use:
|
||||||
|
// - return
|
||||||
|
// - another function call
|
||||||
|
// - additional variables
|
||||||
|
// Scroll down for hints.
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
assert_eq!(10, bigger(10, 8));
|
||||||
|
assert_eq!(42, bigger(32, 42));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// What is Rust's equivalent of the ternary operator?
|
||||||
|
// In C(++) this would be: a>b ? a : b
|
||||||
|
// In Python it would be: a if a>b else b
|
||||||
|
// If you still can't do it: Search online for rust ternary operator
|
||||||
|
|
Loading…
Reference in a new issue