본문 바로가기

Dev. Web/자주 쓰는 스크립트 모음

intersection - 배열 교집합

const intersection = (a, b) => {
  const s = new Set(b);
  return a.filter(x => s.has(x));
};

 

intersection([1, 2, 3], [4, 3, 2]);