JSX:两个JSX集之间的区别

时间:2017-09-02 05:16:12

标签: javascript set jsx

如果我宣布

 var A = new Set(...........);
 var B = new Set(...........);

是否有JSX操作来计算两组A-B的差异?

1 个答案:

答案 0 :(得分:1)

我不确定这与JSX有什么关系,但在MDN上发布了difference方法实现:

var difference = new Set([...A].filter(x => !B.has(x)));

虽然不建议修改内置函数的原型,但您也可以(从同一个MDN链接)将difference添加到Set原型中:

Set.prototype.difference = function(setB) {
    var difference = new Set(this);
    for (var elem of setB) {
        difference.delete(elem);
    }
    return difference;
}

var A = new Set(...........);
var B = new Set(...........);
console.log(A.difference(B))