Created
December 12, 2018 08:58
-
-
Save denchistyakov/c9c25b3e5ceb0c751b7ed18c71e80336 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* @param {string} morseCode Строка закодированная азбукой морзе | |
* @param {object} dict Словарь: ключа символ в азбуке Морзе, значение символ ASCII | |
* @return {string} | |
*/ | |
function decodeMorse(morseCode, dict) { | |
let result = []; | |
const words = morseCode.split(' '); | |
for (let i = 0; i < words.length; i++) { | |
const word = words[i]; | |
const chars = word.split(' '); | |
for (let j = 0; j < chars.length; j++) { | |
const char = chars[j]; | |
result.push(dict[char]); | |
} | |
result.push(' '); | |
} | |
return result.join('').trim(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment