Finding the difference between two sets
We've seen how to combine two sets with the union operation, and find their common elements with the intersection operation. The logical next step is to see how the sets differ. Next, we'll take a look at how to find out what elements one set has that another doesn't. This operation is called a difference
of two sets. An element is in the difference of two sets, if it is in the first set, but not the second.
In this recipe, we'll take a look at how to find the difference between two Set
instances.
Getting ready
This recipe assumes that you already have a workspace that allows you to create and run ES modules in your browser. If you don't, refer to the first two chapters.
How to do it...
- Open your command-line application, and navigate to your workspace.
- Create a new folder named
12-07-set-difference
. - Create a
main.js
file that defines a new class namedRocket
that takes a constructor argumentname
and assigns it to an instance property:
// main.js class...