From c3e8d1938e7c50e563ca7288d229ed5dcff11774 Mon Sep 17 00:00:00 2001 From: Jim Infield Date: Wed, 18 Aug 2021 20:14:15 -0500 Subject: [PATCH] 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 --- src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 5b40d29..6a7e06a 100644 --- a/src/main.rs +++ b/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::().unwrap()) + .filter_map(|e| e.parse::().ok()) // handle invalid parse .collect::>() .chunks(3) .map(|c| (c[0],c[1],c[2]))