From 92a5d0037f0124eb2cdd8637762ca6aa4494fcbd Mon Sep 17 00:00:00 2001 From: fointard Date: Tue, 19 Apr 2022 17:11:27 +0200 Subject: [PATCH] refactor(arc1): improve readability by using functional style --- exercises/standard_library_types/arc1.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/exercises/standard_library_types/arc1.rs b/exercises/standard_library_types/arc1.rs index d167380..f60061e 100644 --- a/exercises/standard_library_types/arc1.rs +++ b/exercises/standard_library_types/arc1.rs @@ -32,12 +32,7 @@ fn main() { for offset in 0..8 { let child_numbers = // TODO joinhandles.push(thread::spawn(move || { - let mut i = offset; - let mut sum = 0; - while i < child_numbers.len() { - sum += child_numbers[i]; - i += 8; - } + let sum: u32 = child_numbers.iter().filter(|n| *n % 8 == offset).sum(); println!("Sum of offset {} is {}", offset, sum); })); }