Created
December 20, 2017 04:43
-
-
Save raychew13/62e356b70232287b0d40f10e57c5ea4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ------------------- intersection of two arrays ------------------- // | |
let setA = new Set([1, 2, 3, 4, 8]); | |
let setB = new Set([4, 3, 2, 10, 7]); | |
let tmpIntersection = new Set([...setA].filter(x => setB.has(x))); | |
console.log(tmpIntersection); | |
// return Set { 2, 3, 4 } | |
console.log( [...setA].filter(x => setB.has(x)) ) | |
// return [ 2, 3, 4 ] | |
// ------------------- setA - setB ------------------- // | |
let setAMinusSetB = new Set([...setA].filter(x => !setB.has(x))); | |
console.log(setAMinusSetB) | |
// return Set { 1, 8 } | |
// ------------------- union of two arrays ------------------- // | |
var union = [...new Set([...setA, ...setB])]; | |
console.log(union) | |
// return . [ 1, 2, 3, 4, 8, 10, 7 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment