toMorse
by thewolff
JavaScript
class MoreseCode {
constructor(str) {
this.str= str;
this.alphabet = {'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': '--..',' ': '/','1': '.----', '2': '..---', '3': '...--', '4': '....-','5': '.....', '6': '-....', '7': '--...', '8': '---..','9': '----.','0': '-----',
}
}
toMorse() {
return Array.from(this.str).map((c, i) => {
return this.alphabet[c]
}).join('')
}
toEnglish() {}
setCharAt(index,chr) {
if(index > this.str.length-1) return this.str;
return chr;
}
}
const m = new MoreseCode('foo')
//console.log(m.toMorse())