Advertisement
alatoru

cas

Jun 2nd, 2020
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const intersectionUnion = (arr1, arr2) => {
  2.   let sharedAll = arr1
  3.     .concat(arr2)
  4.     .filter((x) => arr1.includes(x) && arr2.includes(x));
  5.  
  6.   let intersection = [...new Set(sharedAll)].sort();
  7.   let union = [...new Set(arr1.concat(arr2))].sort();
  8.  
  9.   return [intersection, union];
  10. };
  11.  
  12. console.log(intersectionUnion([1, 2, 3, 4, 4], [4, 5, 9])); // [[4], [1, 2, 3, 4, 5, 9]]
  13. 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