js用Set 實現並集(Union)、交集(Intersect)和差集(Difference)

直接上代碼:javascript let a = new Set([1, 2, 3]); let b = new Set([4, 3, 2]); // 並集 let union = new Set([...a, ...b]); // Set {1, 2, 3, 4} // 交集 let intersect = new Set([...a].filter(x => b.has(x)));//ES
相關文章
相關標籤/搜索