I modify a function for collecting array difference here to handle multi-dimensional array, the code is not working as expected and debugging it has been very problematic because console.log is just displaying content of the code instead of executing it...
function arrDiff(xs, yx, d) {
const apply = f => x => f(x);
const flip = f => y => x => f(x)(y);
const concat = y => xs => xs.concat(y);
const createMap = xs => new Map(xs);
const filter = f => xs => xs.filter(apply(f));
//left difference
const differencel = xs => yx => {
const zs = createMap(yx);
return filter(([k, x]) => zs.has(x) ? false : true)(xs);
};
if (d == 'left') return differencel
//right difference
const difference2 = flip(differencel);
if (d == 'join') return difference2;
//union
if (d == "union") {
const map = new Map([...xs, ...yx]);
return map;
}
// symmetric difference
const difference = yx => xs => concat(differencel(xs)(yx))
(flip(differencel)(xs)(yx));
return difference;
}
const xs = [
['a', 1],
['b', 2],
['c', 2],
['d', 3],
['e', 4],
['f', 5]
];
const ys = [
['g', 0],
['h', 1],
['f', 2],
['b', 3],
['c', 3],
['a', 3],
['e', 6],
['h', 7]
];
console.log(arrDiff(xs, ys, 'left'));