Count Common Words With One Occurrence LeetCode solution in JavaScript
1var countWords = function (words1, words2) {2const map1 = new Map();3const map2 = new Map();4let count = 0;56for (const word of words1) {7map1.set(word, map1.get(word) + 1 || 1);8}9for (const word of words2) {10map2.set(word, map2.get(word) + 1 || 1);11}12for (const word of words1) {13if (map1.get(word) === 1 && map2.get(word) === 1) count++;14}1516return count;17};