Skip to content

Instantly share code, notes, and snippets.

@denchistyakov
Created December 12, 2018 08:58
Show Gist options
  • Save denchistyakov/c9c25b3e5ceb0c751b7ed18c71e80336 to your computer and use it in GitHub Desktop.
Save denchistyakov/c9c25b3e5ceb0c751b7ed18c71e80336 to your computer and use it in GitHub Desktop.
/**
* @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