Rather than keeping two sums, we can negate one of the options (I chose to negate the evens) and compare the sum to 0:
usestd::cmp::Ordering;fncompare_even_to_odd(numbers:implIterator<Item=i64>)->String{letcomparison=numbers.map(|number|ifnumber%2==0{-number}else{number}).sum::<i64>().cmp(&0);matchcomparison{Ordering::Less=>"Even is greater than Odd".to_owned(),Ordering::Equal=>"Even and Odd are the same".to_owned(),Ordering::Greater=>"Odd is greater than Even".to_owned(),}}fnmain(){println!("{}",compare_even_to_odd((&[1,3,4]).iter().map(|a|(*a))));}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Rust
Rather than keeping two sums, we can negate one of the options (I chose to negate the evens) and compare the sum to 0: