最近在看阮一峰老师的《ES6 入门》
在看到Set数据结构实现数组的交集,并集还有差集,但是阮一峰老师实现差集貌似有点问题,特地来做下笔记:
const a = {fn: 1};
const set = new Set([1,1,2,2,3,4,5,5,5,a,'a']);
const b = new Set([6,7,8,9,5,4,3,'a','v']);
// 并集
const union = new Set([...set, ...b]);
// 交集
const intersect = new Set([...set].filter(x => b.has(x)));
// 差集
const difference = new Set([...union].filter(x => (!set.has(x) || !b.has(x))));
原文地址:https://blog.csdn.net/weixin_33709364/article/details/88611813?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task