For this project, I am trying to decode a given Morse code string. Encoded characters are separated by a single space and words are separated by three spaces. I am having a tough time getting past the word spaces. I keep getting "wordundefinedword".
decodeMorse = function(morseCode) {
outPut = "";
for (var i = 0; i < morseCode.split(" ").length; i++) {
if (i === " ") {
outPut += " ";
} else {
outPut += MORSE_CODE[morseCode.split(" ")[i]];
}
}
return outPut;
}
Example: "".... . -.--" "-- .- -."" -> "HEY MAN" Sorry for the weird quotes. It wouldn't show the spaces without the outer ones.