Browse Source

initial codewars worksheet

master
Jim Infield 3 years ago
parent
commit
e8edb49b72
  1. 29
      src/main.rs

29
src/main.rs

@ -1,3 +1,30 @@
fn main() {
println!("Hello, world!");
println!("");
let strs = vec!["is2 Thi1s T4est 3a"];
for str in strs {
println!("{} -> {}", str, order(str));
}
println!("");
}
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];
print!("{:?}\t{:?}\n", n, word);
}
println!("");
words = sentence.split_ascii_whitespace()
.map(|s| format!("{}{}", s.matches(char::is_numeric).collect::<Vec<&str>>()[0],s))
.collect();
words.sort();
words.iter().map(|w| w.trim_start_matches(char::is_numeric)).collect::<Vec<&str>>().join(" ")
}
Loading…
Cancel
Save