ts-data-forge
    Preparing search index...
    • Computes the intersection of two ISet instances.

      Returns a new set containing only the elements that are present in both input sets. This operation is commutative: intersection(a, b) === intersection(b, a).

      Performance: O(min(n, m)) where n and m are the sizes of the input sets.

      Type Parameters

      • K extends Primitive

        The type of the elements.

      Parameters

      • a: ISet<K>

        The first set.

      • b: ISet<K>

        The second set.

      Returns ISet<K>

      A new ISet instance containing elements common to both sets.

      const left = ISet.create<number>([1, 2, 3]);
      const right = ISet.create<number>([2, 4]);

      const overlap = ISet.intersection(left, right);

      assert.deepStrictEqual(Array.from(overlap), [2]);