Skip to content

Instantly share code, notes, and snippets.

@amcsi
Created April 12, 2019 18:16
Show Gist options
  • Save amcsi/987decac0a720578818098d730258fab to your computer and use it in GitHub Desktop.
Save amcsi/987decac0a720578818098d730258fab to your computer and use it in GitHub Desktop.
Morse code codewars kata
// 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