I\'m working on a Greatest Common Factor and Least Common Multiple assignment and I have to list the common factors. Intersection() won\'t work because that removes duplicat
I wrote this extension to solve the problem:
public static IEnumerable Supersect(this IEnumerable a, ICollection b)
=> a.Where(t => b.Remove(t));
example:
var a = new List { 1, 2, 2, 2, 3, 3, 4, 5 };
var b = new List { 1, 1, 2, 2, 3, 3, 3, 4, 4};
var result = a.Supersect(b);
result:
{ 1, 2, 2, 3, 3, 4 }