Distinct array intersection
Find distinct values shared by two arrays while preserving first-array order.
Original Pearto instructional example. Test it in your own environment and adapt it to your requirements.
function intersection(a, b) {
const lookup = new Set(b);
return [...new Set(a)].filter(value => lookup.has(value));
}
console.log(intersection(['red','blue','red'], ['blue','green']));