多次元配列を扱うために配列/マップの違いを収集する関数を修正しようとしましたが、コードが期待通りに機能していません...これは私ですコードjavascriptの2つのMapオブジェクトの違いを計算する関数の記述方法
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;//it is only this one that is working
}
// symmetric difference
const difference = yx => xs => concat(differencel(xs)(yx)(flip(differencel)(xs)(yx));
return difference; //this one is returning function definition
}
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')); //this will dump source code to console
私もコードをデバッグすることはできませんが、再びそれは私がなぜ私は伝統的な配列を使用していない理由でこれを効率的に行うことができます機能を必要としてください、それは私が処理できる以上に複雑になってきているようです...パフォーマンスはここに来る私のポイントです...事前に感謝
あなたがここにエラーがあります: 'フィルタ(([K、X])=> zs.has(x)が偽:?真)(XS);' –
* constの違い= yx => xs => *関数の定義.... –
途中で期待される出力は? –