There are many examples on StackOverflow, but I couldn't find any that handled duplicate values in the way I need.
Given
a= [a, a, b]
b= [a, b]
I want the result to be
result = returnAllElementsFromAThatAreNotInB(a,b)
//result = [a]
result = returnAllElementsFromAThatAreNotInB(b,a)
// result = []
or let’s say I have:
a2 = [1, 2, 2, 3, 4, 4]
b2 = [1, 2, 2, 3, 3, 4]
I want to get:
result = returnAllElementsFromAThatAreNotInB(a2,b2)
//console.log(result) = [4]
result = returnAllElementsFromAThatAreNotInB(b2,a2)
//console.log(result) = [3]
the difference and symmetrical difference shown here How to get the difference between two arrays in JavaScript?
don't work. They empty arrays because it's checking only values, not instances of elements... the problem is I care about the number of elements of a value, not just the value.