[JavaScript] Code Skill
in Devlog on JavaScript, Devlog, Code, Skill
배열
두개 배열이 있을 때
let arr1 = [1, 2, 3];
let arr2 = [2, 3, 4, 5];
- 차집합
let difference = arr1.filter((x) => !arr2.includes(x)); // 결과 1
- 교집합
let difference = arr1.filter((x) => arr2.includes(x)); // 결과 2, 3
- 배타적 논리합
let difference = arr1.filter(x => !arr2.includes(x)).concat(arr2.filter(x => !arr1.includes(x)));