Javascript Set check super set

Description

Javascript Set check super set

function isSuperset(set, subset) {
    for (let elem of subset) {
        if (!set.has(elem)) {
            return false
        }//w  w  w  . ja  va 2  s .  c om
    }
    return true
}

let set1 = new Set();
let set2 = new Set();

set1.add(1);
set1.add(2);
set1.add(3);

set2.add(2);
set2.add(3);

let a = isSuperset(set1, set2);
console.log(a);

a = isSuperset(set2, set1);
console.log(a);



PreviousNext

Related