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