1
0
Fork 0
mirror of https://github.com/rust-lang/rustlings.git synced 2024-05-19 15:36:07 +02:00

Make @ConnyOnny's example be 1st example in the `if` section! 🎉

This commit is contained in:
Carol (Nichols || Goulding) 2015-11-17 17:59:18 -05:00
parent f1ce5f4454
commit c2bd282af2
3 changed files with 53 additions and 51 deletions

File diff suppressed because one or more lines are too long

51
ex6.rs
View File

@ -1,51 +0,0 @@
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

47
if/if1.rs Normal file
View File

@ -0,0 +1,47 @@
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));
}
// It's possible to do this in one line if you would like!
// Some similar examples from other languages:
// - In C(++) this would be: `a > b ? a : b`
// - In Python this would be: `a if a > b else b`
// Remember in Rust that:
// - the `if` condition does not need to be surrounded by parentheses
// - `if`/`else` conditionals are expressions
// - Each condition is followed by a `{}` block.