mirror of
https://gitlab.com/mfocko/CodeWars.git
synced 2024-11-09 19:19:07 +01:00
19 lines
417 B
Rust
19 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())
|
||
|
}
|