JavaScript Set Logic

JavaScript Set Logic
JavaScript Set Logic can be used to perform mathematical set operations such as:
Union
Intersection
Difference
Subset Check
These are useful in algorithms, data filtering, search operations, and comparisons.
Union (Combine Two Sets)
Union = All unique elements from both sets
Output:
Intersection (Common Elements)
Intersection = Elements present in both sets
Output:
Difference (Elements in A but not in B)
Output:
Symmetric Difference (Elements NOT in both)
Elements unique to either set, but not shared.
Output:
Subset Check (Is A a subset of B?)
Example:
Bonus: Superset Check
Summary Table
| Operation | Result Example |
|---|---|
| Union | {1,2,3} + {3,4} → {1,2,3,4} |
| Intersection | {1,2,3} ∩ {2,3,4} → {2,3} |
| Difference | {1,2,3} - {2,3} → {1} |
| Symmetric Difference | Unique in both → {1,4} |
| Subset Check | {1,2} ⊆ {1,2,3} → true |
