Skip to content

Instantly share code, notes, and snippets.

@e-mihaylin
Created June 26, 2018 13:33
Show Gist options
  • Select an option

  • Save e-mihaylin/b55655bc4c9406d1237b6f5a2bfc4bd7 to your computer and use it in GitHub Desktop.

Select an option

Save e-mihaylin/b55655bc4c9406d1237b6f5a2bfc4bd7 to your computer and use it in GitHub Desktop.
const decodeMorse = morseCode => morseCode
.trim()
.split` `
.map(e => morseDictionary[e])
.join``
.replace(/\s+/g, ' ');
const morseDictionary = {
'...---...': 'SOS',
'-.-.--': '!',
'.-.-.-': '.',
'.-': 'A',
'-...': 'B',
'-.-.': 'C',
'-..': 'D',
'.': 'E',
'..-.': 'F',
'--.': 'G',
'....': 'H',
'..': 'I',
'.---': 'J',
'-.-': 'K',
'.-..': 'L',
'--': 'M',
'-.': 'N',
'---': 'O',
'.--.': 'P',
'--.-': 'Q',
'.-.': 'R',
'...': 'S',
'-': 'T',
'..-': 'U',
'...-': 'V',
'.--': 'W',
'-..-': 'X',
'-.--': 'Y',
'--..': 'Z',
'': ' '
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment