I see a lot of posts about how to get the difference and symmetric difference of an array in javascript, but I haven't found anything on how to find the difference, including duplicates.
For example:
let original = [1];
let updated = [1, 1, 2];
difference(updated, original);
// Expect: [1, 2]
Is there an elegant way to do this? I'm open to solutions using plain javascript or lodash.
Thanks!
UPDATE
To clarify, an infinite number of duplicates should be supported. Another example:
let original = [1, 1];
let updated = [1, 1, 1, 1, 1, 2];
difference(updated, original);
// Expect: [1, 1, 1, 2]
UPDATE 2
I realized that there may be some confusion on the original requirements. It is true that infinite duplicates should be supported, but the order should not affect the output.
Example:
let original = [1, 1, 2];
let updated = [1, 2, 1, 1, 1];
difference(updated, original);
// Expect: [1, 1]