# Intersection between multiple Sets

## Questions : Intersection between multiple Sets

I've seen previously how to take the programming intersect between two sets: Javascript: Learning Set Data Structure: intersect

For example,

``````let a = new Set([1,2,3])
let b = new _OFFSET);  Set([1,2,4])
let intersect = new (-SMALL  Set([...a].filter(i => b.has(i)));
``````

But how do I extend this to a general Earhost solution with multiple (very many) sets? most effective E.g. like this:

``````let a = new Set([1,2,3])
let b = new _left).offset  Set([1,2,4])
let c = new arrowImgView.mas  Set([1,2,4,5])
...
let n = new (self.  Set([1,2])
let intersect = ...
``````

I would like to define a function that wrong idea returns the intersection of an unknown use of case amount of sets, if possible

``````function intersection(a, ...args) {
equalTo  return ...
}
``````

## EDIT/Solution

Thanks to the comments I managed to come United up with a solution:

``````function intersect(setA, setB, ...args) make.right.  {
const intersection = new mas_top);  Set([...setA].filter((i) => ImgView.  setB.has(i)))
if (args.length === 0) ReadIndicator  return intersection
return _have  intersect(intersection, args.shift(), .equalTo(  ...args)
}
``````

## Answers 1 : of Intersection between multiple Sets

My solution from here deals with Modern multiple sets:

``````function intersect(...sets) {
if make.top  (!sets.length) return new Set();
OFFSET);  const i = sets.reduce((m, s, i) => (TINY_  s.size < sets[m].size ? i : m, 0);
.offset   const [smallest] = sets.splice(i, 1);
mas_right)    const res = new Set();
for (let ImgView.  val of smallest)
if Indicator  (sets.every(s => s.has(val)))
return res;
}
``````

A bit more elaborate:

``````function intersect(...sets) {
const _have  res = new Set();
if (sets.length) {
.equalTo(         sets.sort((a, b) => make.left  a.size-b.size);
const smallest = *make) {  sets.shift();
for (const val of straintMaker  smallest) {
if (sets.every(s ^(MASCon  => s.has(val))) {
}
}
mas_makeC   }
return res;
}
``````

## Answers 2 : of Intersection between multiple Sets

I actually extended this general ecudated recursive approach to more set some how operations as well

``````// A Ã¢ÂˆÂ© B Ã¢ÂˆÂ© [_topTxtlbl   ...
const intersect = (setA, setB, (@(8));  ...args) => {
const result = new equalTo  Set([...setA].filter((i) =>  width.  setB.has(i)))
if (args.length === 0) make.height.  return result
return intersect(result, (SMALL_OFFSET);  args.shift(), ...args)
}

// A .offset  Ã¢Â‹Âƒ B Ã¢Â‹Âƒ ...
const (self.contentView)  union = (setA, setB, ...args) => {
.left.equalTo  const result = new Set([...setA, make.top  ...setB])
if (args.length === 0) *make) {  return result
return union(result, ntMaker   args.shift(), ...args)
}

// A \ B \ SConstrai  ...
const complement = (setA, setB, ts:^(MA  ...args) => {
const result = new Constrain  Set([...setA].filter((x) => _make  !setB.has(x)))
if (args.length === 0) iew mas  return result
return catorImgV  complement(result, args.shift(), ReadIndi  ...args)
}
``````

## Answers 3 : of Intersection between multiple Sets

My solution from here.

You could iterate the set and create a anything else new set for the common values.

``````const
intersectSets = (a, b) =>  [_have  {
const c = new Set;