From 802e6ac2706115935970b8c71d1ad99cb621b353 Mon Sep 17 00:00:00 2001 From: Constantin Berhard Date: Wed, 28 Oct 2015 00:45:39 +0100 Subject: [PATCH] exercise for the ternary operator i.e. if-then-else *expression* in Rust --- ex6.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 ex6.rs diff --git a/ex6.rs b/ex6.rs new file mode 100644 index 0000000..7302a2a --- /dev/null +++ b/ex6.rs @@ -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 +