1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-09 02:59:06 +01:00
CodeWars/6kyu/decode_the_morse_code/solution.rs

19 lines
417 B
Rust
Raw Normal View History

mod preloaded;
use preloaded::MORSE_CODE;
// MORSE_CODE is `HashMap<String, String>`. e.g. ".-" -> "A".
fn decode_morse(encoded: &str) -> String {
let mut result = String::new();
encoded.split(" ").map(|x| x.trim()).for_each(|x| {
x.split_whitespace().for_each(|c| {
result += MORSE_CODE.get(c).unwrap();
});
result += " ";
});
String::from(result.trim())
}