Browse Source

Initial Codewars submission..

add check for empty string (look for better way)
use filter_map() on integer parsing, this method does not panic
filter_map sends an empty value which is converted to zero
master
Jim Infield 3 years ago
parent
commit
c3e8d1938e
  1. 3
      src/main.rs

3
src/main.rs

@ -47,11 +47,12 @@ fn main() {
} }
fn stati(s: &str) -> String { fn stati(s: &str) -> String {
if s.is_empty() { return "".to_string() } // handle empty string
let mut t = let mut t =
s.split(", ") s.split(", ")
.map( .map(
|m| m.split('|') |m| m.split('|')
.map(|e| e.parse::<usize>().unwrap())
.filter_map(|e| e.parse::<usize>().ok()) // handle invalid parse
.collect::<Vec<usize>>() .collect::<Vec<usize>>()
.chunks(3) .chunks(3)
.map(|c| (c[0],c[1],c[2])) .map(|c| (c[0],c[1],c[2]))

Loading…
Cancel
Save