Browse Source

function committed to codewars

master
Jim Infield 3 years ago
parent
commit
0337a65e5d
  1. 21
      src/main.rs

21
src/main.rs

@ -11,23 +11,16 @@ fn main() {
} }
fn order(sentence: &str) -> String { fn order(sentence: &str) -> String {
let mut words = vec![];
for word in sentence.split_whitespace() {
let n = word.matches(char::is_numeric).collect::<Vec<&str>>()[0];
println!("{:?}\t{:?}", n, word);
}
println!();
words = sentence.split_ascii_whitespace()
.map(|s| format!("{}{}", s.matches(char::is_numeric).collect::<Vec<&str>>()[0],s))
// Iterate over non-whitespace 'words'
let mut words: Vec<String> = sentence.split_whitespace()
// Insert copy of first (only) digit at the beginning
.map(|s| format!("{}{}",
s.matches(char::is_numeric).collect::<Vec<&str>>()[0], s))
.collect(); .collect();
words.sort(); words.sort();
// Remove first character and join with spaces
words.iter().map(|w| &w[1..]) words.iter().map(|w| &w[1..])
.collect::<Vec<&str>>() .collect::<Vec<&str>>()
.join(" ")
.join(" ").to_string()
} }
Loading…
Cancel
Save