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 {
if s.is_empty() { return "".to_string() } // handle empty string
let mut t =
s.split(", ")
.map(
|m| m.split('|')
.map(|e| e.parse::<usize>().unwrap())
.filter_map(|e| e.parse::<usize>().ok()) // handle invalid parse
.collect::<Vec<usize>>()
.chunks(3)
.map(|c| (c[0],c[1],c[2]))

Loading…
Cancel
Save