Browse Source

switch to accumulator for time calculations

master
Jim Infield 3 years ago
parent
commit
594ea33b28
  1. 13
      src/main.rs

13
src/main.rs

@ -8,9 +8,9 @@ fn main() {
println!();
// for arg in args {
// println!("{:?}\n{:?}\n", arg, stati(arg));
// };
for arg in &args {
println!("{:?}\n{:?}\n", arg, stati(arg));
};
let strings = args[0];
@ -53,11 +53,7 @@ fn stati(s: &str) -> String {
.map(
|m| m.split('|')
.filter_map(|e| e.parse::<usize>().ok()) // handle invalid parse
.collect::<Vec<usize>>()
.chunks(3)
.map(|c| (c[0],c[1],c[2]))
.map(|(h,m,s)| h*3600 + m*60 + s)
.sum()
.fold(0, |a, i| a*60+i) // switch to accumulater
)
.collect::<Vec<usize>>();
@ -96,5 +92,6 @@ mod tests {
"Range: 01|01|18 Average: 01|38|05 Median: 01|32|34");
dotest("02|15|59, 2|47|16, 02|17|20, 2|32|34, 2|17|17, 2|22|00, 2|31|41",
"Range: 00|31|17 Average: 02|26|18 Median: 02|22|00");
dotest("","");
}
}
Loading…
Cancel
Save