diff --git a/exercises/decimal/example.rs b/exercises/decimal/example.rs index ae87ebc8b..49e10a11b 100644 --- a/exercises/decimal/example.rs +++ b/exercises/decimal/example.rs @@ -75,10 +75,10 @@ impl Decimal { &lower_precision.digits * pow(BigInt::from(10_usize), precision_difference); lower_precision.decimal_index += precision_difference; } - if one.decimal_index < two.decimal_index { - expand(&mut one, &two) - } else if one.decimal_index > two.decimal_index { - expand(&mut two, &one) + match one.decimal_index.cmp(&two.decimal_index) { + std::cmp::Ordering::Equal => {}, + std::cmp::Ordering::Less => expand(&mut one, &two), + std::cmp::Ordering::Greater => expand(&mut two, &one), } assert_eq!(one.decimal_index, two.decimal_index); } diff --git a/exercises/palindrome-products/example.rs b/exercises/palindrome-products/example.rs index a08950c14..75ff47b50 100644 --- a/exercises/palindrome-products/example.rs +++ b/exercises/palindrome-products/example.rs @@ -42,15 +42,15 @@ pub fn palindrome_products(min: u64, max: u64) -> Option<(Palindrome, Palindrome result = match result { None => Some((Palindrome::new(a, b), Palindrome::new(a, b))), Some((mut minp, mut maxp)) => { - if a * b < minp.value() { - minp = Palindrome::new(a, b); - } else if a * b == minp.value() { - minp.insert(a, b); + match (a * b).cmp(&minp.value()) { + std::cmp::Ordering::Greater => {}, + std::cmp::Ordering::Less => minp = Palindrome::new(a, b), + std::cmp::Ordering::Equal => minp.insert(a, b), } - if a * b > maxp.value() { - maxp = Palindrome::new(a, b); - } else if a * b == maxp.value() { - maxp.insert(a, b); + match (a * b).cmp(&maxp.value()) { + std::cmp::Ordering::Less => {}, + std::cmp::Ordering::Greater => maxp = Palindrome::new(a, b), + std::cmp::Ordering::Equal => maxp.insert(a, b), } Some((minp, maxp)) } diff --git a/exercises/perfect-numbers/example.rs b/exercises/perfect-numbers/example.rs index 30899490c..04cdf49f9 100644 --- a/exercises/perfect-numbers/example.rs +++ b/exercises/perfect-numbers/example.rs @@ -3,12 +3,10 @@ pub fn classify(num: u64) -> Option { return None; } let sum: u64 = (1..num).filter(|i| num % i == 0).sum(); - if sum == num { - Some(Classification::Perfect) - } else if sum < num { - Some(Classification::Deficient) - } else { - Some(Classification::Abundant) + match sum.cmp(&num) { + std::cmp::Ordering::Equal => Some(Classification::Perfect), + std::cmp::Ordering::Less => Some(Classification::Deficient), + std::cmp::Ordering::Greater => Some(Classification::Abundant), } }