-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmorseCode.js
More file actions
19 lines (15 loc) · 1.11 KB
/
Copy pathmorseCode.js
File metadata and controls
19 lines (15 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// The Morse code encodes every character as a sequence of "dots" and "dashes".
// For example, the letter A is coded as ·−, letter Q is coded as −−·−, and digit 1 is coded as ·−−−−.
// The Morse code is case-insensitive, traditionally capital letters are used.
// When the message is written in Morse code, a single space is used to separate the character codes and 3 spaces are used to separate words.
// For example, the message HEY JUDE in Morse code is ···· · −·−− ·−−− ··− −·· ·.
// //Your task is to implement a function that would take the morse code as input and return a decoded human-readable string.
// NOTE: For coding purposes you have to use ASCII characters . and -, not Unicode characters.
// The Morse code table is preloaded for you as a dictionary, feel free to use it:
let morseCode = '.... . -.-- .--- ..- -.. .';
decodeMorse = function(morseCode){
let threeSpace = morseCode.split(' ')
let conversion = []
threeSpace.forEach(word => conversion.push(word.split(' ').map( letter => MORSE_CODE[letter]).join('')))
return conversion.join(' ').trim()
}