如果我宣布
var A = new Set(...........);
var B = new Set(...........);
是否有JSX操作来计算两组A-B的差异?
答案 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))