Javascript Array isSubsetOf(set)

Description

Javascript Array isSubsetOf(set)


Array.prototype.isSubsetOf = function (set) {
  const subset = new Set(this);//from   w w  w . j a v a  2s.  c o m
  const superSet = new Set(set);

  return !(new Set([...subset]
    .filter((element) => !superSet.has(element))).size);
};

console.log(['cat', 'dog', 'cow'].isSubsetOf(['dog', 'cow', 'fox', 'cat']));



PreviousNext

Related