Set operators are common set operations that makes working with arrays easier. All set operations return an array except for has which returns a boolean value. The following operations are possible with sets:
Table of Contents |
---|
Given arrays (sets) A and B:
intersection (A ∩ B):
The set of all objects that are a member of both A and B
...
Code Block | ||
---|---|---|
| ||
A.intersection(B); |
Union (A ∪ B):
The set of all objects that are a member of A or B (or both)
...
Code Block | ||
---|---|---|
| ||
A.union(B); |
difference (A \ B):
The set of all members of A that are not members of B
...
Code Block | ||
---|---|---|
| ||
A.difference(B); |
has (B ⊆ A):
B is a subset of A (or it could be read as A is a superset of B)
...
Code Block | ||
---|---|---|
| ||
A.has(B); |
once:
Set of elements e that only appear 1 time in A
...
Code Block | ||
---|---|---|
| ||
A.once(); |
duplicates:
Set of elements e that appear more than once in A
...
Code Block | ||
---|---|---|
| ||
A.duplicates(); |
unique:
Set of (unique) elements e belonging to A
...