Uncommon Words from Two Sentences

LeetCode 題目: 884. Uncommon Words from Two Sentences

My solution:

/**
 * @param {string} s1
 * @param {string} s2
 * @return {string[]}
 */
let uncommonFromSentences = (s1, s2) => {
  const zipArray = s1.split(" ").concat(s2.split(" "));
  let map = new Map();
  for (let i = 0; i < zipArray.length; i++) {
    map.has(zipArray[i])
      ? map.set(zipArray[i], map.get(zipArray[i]) + 1)
      : map.set(zipArray[i], 1);
  }
  return Array.from(map)
    .filter(([key, value]) => value === 1)
    .map(([key, value]) => key);
};
profile-image
Hi, 我是 Zeki。目前為一名前端工程師。我相信科技始終來自於人性,是用來幫助人們過上更有品質的生活的,但願也希望如此。