Created
April 12, 2019 18:16
-
-
Save amcsi/987decac0a720578818098d730258fab to your computer and use it in GitHub Desktop.
Morse code codewars kata
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Preloaded: | |
// | |
// struct MorseDecoder { | |
// morse_code: HashMap<String, String>, | |
// } | |
// | |
// MorseDecoder::new() populates the morse_code map, e.g. ".-" -> "A". | |
impl MorseDecoder { | |
fn decode_morse(&self, encoded: &str) -> String { | |
let ref morse_code = self.morse_code; | |
println!("{:?}", morse_code); | |
println!("{:?}", &&morse_code.get("asdfdsaf").unwrap_or("trying to do unwrap_or")); | |
encoded.split(" ").map(|word: &str| -> String { | |
word.split(" ").map(|letter: &str| -> String { | |
println!("{}", letter); | |
morse_code.get(letter).unwrap().to_owned() | |
}).collect::<Vec<_>>().join("") | |
}).collect::<Vec<_>>().join(" ") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment