Decode the Morse code

JavaScript

decodeMorse = function(morseCode) {
  var decodedMessage = "";
  var chars = morseCode.trim().replace(/  /g, ' ').split(' ');

  for (let i = 0; i < chars.length; i++) {
    let currentChar = MORSE_CODE[chars[i]];
    if (!currentChar) currentChar = " ";

    decodedMessage += currentChar;
  }

  return decodedMessage;
}

Tags

  1. javascript (Private)
  2. 6-kyu (Private)
  3. codewars (Private)
  4. answer (Private)