Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Morse Decoder by vincent.tscherter
var MORSE = {'.-': 'a', '-...': 'b', '-.-.': 'c',
'-..': 'd', '.': 'e', '..-.': 'f',
'--.': 'g', '....': 'h', '..': 'i',
'.---': 'j', '-.-': 'k', '.-..': 'l',
'--': 'm', '-.': 'n', '---': 'o',
'.--.': 'p', '--.-': 'q', '.-.': 'r',
'...': 's', '-': 't', '..-': 'u',
'...-': 'v', '.--': 'w', '-..-': 'x',
'-.--': 'y', '--..': 'z', '-----': '0',
'.----': '1', '..---': '2', '...--': '3',
'....-': '4', '.....': '5', '-....': '6',
'--...': '7', '---..': '8', '----.': '9'
};
function morseDecoder(code) {
code = code.split(' ').map( c => MORSE[c] || ' ' ).join('').replace(/ /g,' ');
return code[0].toUpperCase() + code.substr(1);
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example:')
console.log(morseDecoder('... --- ...'))
// These "asserts" are used for self-checking and not for an auto-testing
assert.equal(morseDecoder("... --- -- . - . -..- -"), "Some text")
assert.equal(morseDecoder("..--- ----- .---- ---.."), "2018")
assert.equal(morseDecoder(".. - .-- .- ... .- --. --- --- -.. -.. .- -.--"), "It was a good day")
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
May 24, 2018
Comments: