From 0337a65e5de8cb34075902358eff6395aa032195 Mon Sep 17 00:00:00 2001 From: Jim Infield Date: Mon, 2 Aug 2021 10:12:09 -0500 Subject: [PATCH] function committed to codewars --- src/main.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4f6dc17..a732d2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,23 +11,16 @@ fn main() { } fn order(sentence: &str) -> String { - - let mut words = vec![]; - - for word in sentence.split_whitespace() { - let n = word.matches(char::is_numeric).collect::>()[0]; - println!("{:?}\t{:?}", n, word); - } - println!(); - - words = sentence.split_ascii_whitespace() - .map(|s| format!("{}{}", s.matches(char::is_numeric).collect::>()[0],s)) + // Iterate over non-whitespace 'words' + let mut words: Vec = sentence.split_whitespace() + // Insert copy of first (only) digit at the beginning + .map(|s| format!("{}{}", + s.matches(char::is_numeric).collect::>()[0], s)) .collect(); - + words.sort(); - + // Remove first character and join with spaces words.iter().map(|w| &w[1..]) .collect::>() - .join(" ") - -} + .join(" ").to_string() +} \ No newline at end of file