1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-16 20:56:57 +02:00
CodeWars/6kyu/decode_the_morse_code/solution.rs
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

18 lines
417 B
Rust

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())
}