Package Exports
- set-utilities
- set-utilities/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (set-utilities) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Set Utilities
This library is a collection of utility functions that operate with JavaScript Sets.
Each function, as derived from Set Theory, is built to operate on n-ary sets by accepting variable arguments. Additionally, each function operates with the principals of immutability: none of the input sets are modified in the process or result of calculation.
Set Operations:
difference: A ∖ B
The difference of two sets contains all the elements of the first set that are not contained in the second (or thereafter).
import { difference } from 'set-utilities';
const differenceAB = difference(setA, setB);
const differenceABC = difference(setA, setB, setC);intersection: A ∩ B
The intersection of two sets contains all the elements each contained in both of the sets.
import { intersection } from 'set-utilities';
const intersectionAB = intersection(setA, setB);
const intersectionABC = intersection(setA, setB, setC);union: A ∪ B
The union of two sets contains all the elements contained in either set (or both sets).
import { union } from 'set-utilities';
const unionAB = union(setA, setB);
const unionABC = union(setA, setB, setC);symmetric difference (xor): A ∆ B
The symmetric difference of two sets contains only the unique elements of each set.
import { xor } from 'set-utilities';
const xorAB = xor(setA, setB);
const xorABC = xor(setA, setB, setC);Set Comparisons:
equivalence: A ∼ B
Sets are equivalent if they have the same cardinality, and there is a bijection between the values contained in each set.
import { equivalence } from 'set-utilities';
const isEquivalentAB = equivalence(setA, setB);
const isEquivalentABC = equivalence(setA, setB, setC);disjoint: A ∩ B = ∅
Sets are disjoint if they have no elements in common.
import { disjoint } from 'set-utilities';
const isDisjointAB = disjoint(setA, setB);
const isDisjointABC = disjoint(setA, setB, setC);subset: A ⊆ B
A set is a subset of another if all of its elements are elements of the other set.
import { subset } from 'set-utilities';
const isSubsetAB = subset(setA, setB);
const isSubsetABC = subset(setA, setB, setC);proper subset: A ⊂ B
A set is a proper subset of another if all of its elements are elements of the other set, and it has a lower cardinality than the other set.
import { properSubset } from 'set-utilities';
const isProperSubsetAB = properSubset(setA, setB);
const isProperSubsetABC = properSubset(setA, setB, setC);superset: A ⊇ B
A set is a superset of another if it contains all the elements contained in the other set.
import { superset } from 'set-utilities';
const isSupersetAB = superset(setA, setB);
const isSupersetABC = superset(setA, setB, setC);proper superset: A ⊃ B
A set is a proper superset of another if it contains all the elements contained in the other set, and it has a greater cardinality than the other set.
import { properSuperset } from 'set-utilities';
const isProperSupersetAB = properSuperset(setA, setB);
const isProperSupersetABC = properSuperset(setA, setB, setC);Set Ordering:
sort:
An immutable sorting operation for sets.
import { sort } from 'set-utilities';
const sorted = sort(setA);
const sortedByComparator = sort(setA, comparatorFunction);