Javascript Set difference operation

Description

Javascript Set difference operation

function differenceSet(setA, setB) {
    var difference = new Set(setA);
    for (var elem of setB) {
        difference.delete(elem);//from   w  w  w.  java 2 s  . co  m
    }
    return difference;
}
var setA = new Set([1, 2, 3, 4]),
    setB = new Set([2, 3]);

let a = differenceSet(setA, setB); // Set(2) {1, 4}
console.log(a);



PreviousNext

Related