Subset

The last set operation we will cover is the subset. An example of the mathematical concept of subset is that A is a subset of (or is included in) B, and this is denoted by:

The set is defined as:

This means that for every x (element) that exists in A, it also needs to exist in B. The following diagram exemplifies when A is a subset of B:

Now, let's create the isSubsetOf method in our Set class using the following code:

isSubsetOf(otherSet) ...

Get Learning JavaScript Data Structures and Algorithms - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.