804. Unique Morse Code Words
var uniqueMorseRepresentations = function(words) {
const morseCode = {
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: "--..",
}
const num = new Set()
for (let word of words) {
let str = '';
for (let i = 0; i < word.length; i++) {
str += morseCode[word[i]]
}
num.add(str)
}
return num.size
};