Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const intersectionUnion = (arr1, arr2) => {
- let sharedAll = arr1
- .concat(arr2)
- .filter((x) => arr1.includes(x) && arr2.includes(x));
- let intersection = [...new Set(sharedAll)].sort();
- let union = [...new Set(arr1.concat(arr2))].sort();
- return [intersection, union];
- };
- console.log(intersectionUnion([1, 2, 3, 4, 4], [4, 5, 9])); // [[4], [1, 2, 3, 4, 5, 9]]
- console.log(intersectionUnion([1, 2, 3], [4, 5, 6])); // [[], [1, 2, 3, 4, 5, 6]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement