Using lodash, I want to find all the elements between two arrays that are different, basically the opposite or inverse of _.intersection[with|by]. Of course I reviewed _.difference[with|by] but it's not an inverse version of _.intersection as it only compares the first array with the second, rather than comparing them against each other. The closest I was able to get is very cludgy which has motivated me to ask here if I'm missing a more efficient and/or elegant option. I'm only interested in lodash based solutions.
Here is the closest I could come up with to get a unique array of values that are different between both arrays. I'm interested in values with id properties that aren't in both arrays and values with matching id properties but different v properties.
const n = [{id: 0, v: 9.7}, {id: 1, v: 1.7}, {id: 3, v: 2.6}, {id: 4, v: 1.89}]
const o = [{id: 1, v: 1.7}, {id: 3, v: 3.6}, {id: 7, v: 0.89}, {id: 4, v: 1.89}]
_.uniqBy(_.concat(
_.differenceWith(n, o, _.isEqual), _.differenceWith(o, n, _.isEqual)), 'id')
That code will yield:
[{id: 0, v: 9.7}, {id: 3, v: 2.6}, {id: 7, v: 0.89}]