Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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
languagejavascript
A.intersection(B);

Union (A ∪ B):

 The set of all objects that are a member of A or B (or both)

...

Code Block
languagejavascript
A.union(B);

difference (A \ B):

 The set of all members of A that are not members of B

...

Code Block
languagejavascript
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
languagejavascript
A.has(B);

once:

 Set of elements e that only appear 1 time in A

...

Code Block
languagejavascript
A.once();

duplicates:

 Set of elements e that appear more than once in A

...

Code Block
languagejavascript
A.duplicates();

unique:

 Set of (unique) elements e belonging to A

...