I would like to create an algorithm (or use an existing js library/fn) that would merge two arrays together so that
- values are dropped from the results that are not in the replacing array compared to original
- value is added if not exist in the original array
- duplicates are not added
- Arrays do not have to be the same size
E.g.
const originalArray = [1,2,3];
const replacingArray = [1,5,3,4]; // 2 is missing and 5,4 are new compared to the original
const result = merge(originalArray, replacingArray);
console.log(result) // [1,5,3,4]
How could I achieve that? What would be the merge
function?