0

I have two arrays

const arr1 = [{id: 1,name: 'Diego', age: 23,}, 
              {id: 2,name: 'Brian',age: 18,}, 
              {id: 4,name: 'Lonaro', age: 21,}];


const arr2 = [{id: 1,name: 'Diego',age: 23,}, 
              {id: 2,name: 'Brian',age: 18,}, 
              {id: 3,name: 'Pikachu',age: 88,}];

Need to get arr1 LEFT OUTER JOIN arr2 = [{id: 4,name: 'Lonaro', age: 21,}]

and Need to get arr1 RIGHT OUTER JOIN arr2 = [{id: 3,name: 'Pikachu',age: 88,}]

and Need to get arr1 INTERSECTION arr2 = [{id: 1,name: 'Diego', age: 23,}, {id: 2,name: 'Brian',age: 18,},]

using typescript

1 Answers1

1
  1. Use a difference(x, y) method

  2. Use a difference(y, x) method - note that the arrays order is reversed

  3. Use an intersection(x, y) method

You can find them in lodash or ramdajs or roll out yourself.

Ori Drori
  • 183,571
  • 29
  • 224
  • 209