s1
, s2
에 등장하는 모든 단어의 빈도를 확인한다.function uncommonFromSentences(s1: string, s2: string): string[] {
const frequent = new Map<string, number>()
const result = []
for(const word of s1.split(' ')) frequent.set(word, (frequent.get(word) ?? 0) + 1)
for(const word of s2.split(' ')) frequent.set(word, (frequent.get(word) ?? 0) + 1)
for(const [key, value] of frequent) {
if(value > 1) continue
result.push(key)
}
return result
};