Now that we've got a good handle on sets, it's time to start performing some set operations. Sets are unordered groups of things; something you might want to do is to combine two groups into one. This operation is called a union
of two sets. An element is in the union of two sets, if it exists in either of them.
In this recipe, we'll take a look at how to create a union of two Set
instances.
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.
- Open your command-line application, and navigate to your workspace.
- Create a new folder named
12-05-set-union
. - 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 Rocket { constructor(name) { this.name = name; } }
- Create a function called
union
that takes two set arguments...