Created
January 14, 2017 17:55
-
-
Save anoopelias/1fe49e1432ca9b7712fd5106a72ec46b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::cmp::max; | |
fn largest2(arr: [i32; 5]) -> i32 { | |
arr.iter().fold(0, |num, &x| { | |
max(num, x) | |
}) | |
} | |
fn largest3(arr: [i32; 5]) -> i32 { | |
arr.iter().fold(0, max) // Do Not compile! | |
} | |
fn main() { | |
let arr = [5, 6, 2, 9, 3]; | |
let l2 = largest2(arr); | |
let l3 = largest3(arr); | |
println!("Largest2 : {}", l2); | |
println!("Largest3 : {}", l3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment