FullSet
Full-Set is a wrapper class around the native ES6 set object which adds the classical set operations.
For pedagogical purposes mostly, probably not production ready.
Install
npm i --save full-set
Requirements
This library relies on ES6 Sets, and so either a recent version of Node or the browsers will be required
Documentation
Methods
constructor
add
clone
contains
equal
remove
values
union
intersect
complement
relativeComplement
symmetricDifference
crossProduct
powerSetIter
powerSet
cardinality
size
constructor
Creates and adds elements to a set.
Arguments
...elements
- Variadic, any number of elements as arguments
Example
let A = '1''2''3';
add
Adds elements to the set
Arguments
...elements
- Variadic, any number of elements as arguments
let A = 'A''B'; A;
clone
Creates a copy of a set
Example
let A = 'TOAST''EGGS''BACON'; let B = A;
contains
Given an element will reply with a boolean if the set containts that element
Arguments
element
- An element to query the set for
Example
let A = 'A''B''C''D''E'; A //true
equal
This will compare another set for equality, when both sets contain the same elements
Arguments
other_set
- Another FullSet object to compare
Example
let A = '1''2'; let B = '1''2'; let E = '1''2''1''2'; A //equal sets should equal A //duplicates don't matter
remove
Remove elements from a set
Arguments
...elements
- Variadic, any number of elements to remove from the set as arguments
Example
let A = 'A''B''C''D''E'; A //true A //true A A //false A //false
values
Returns an iterator of the elements in the set
Example
let A = 'A''B''C''D''E'; let iterator = A; iteratornextvalue //A;
union
Create a new set which has all the elements of both sets.
Arguments
other_set
- Another FullSet object
Example
let A = "A""B"; let B = "D""E"; let C = A; //A,B,D,E
intersect
Create a new set which only has elements this set and the other set contain.
Arguments
other_set
- Another FullSet object
Example
let A = 1234; let B = 3456; let inty = A; //3,4
complement
Given a universe set, it will return all of the elements not in this set.
Arguments
other_set
- Another FullSet object
Example
let universe = 12345; let A = 1; let compA = A; //2,3,4,5
relativeComplement
Given another set, it will return a set of elements that are only in this set relative to the other set.
Arguments
other_set
- Another FullSet object
Example
let A = 1234; let B = 3456; let AminusB = A; //1,2
symmetricDifference
Given another set, it will return a set of elements that are in this set and in the other set, but not the elements that are in both.
Arguments
other_set
- Another FullSet object
Example
let A = 1234; let B = 3456; let AtriangleB = A; // 1,2,5,6
crossProduct
Given another set, it will return a new set of ordered pairs (Arrays) of every combination of this set elements and the other sets elements.
Arguments
other_set
- Another FullSet object
Example
let A = 12; let B = 34; let AcrossB = A; //[1,3],[2,3],[1,4],[2,4]
powerSetIter
Iterator for all subsets of the set
Example
let A = 123; let powerIterator = A; powerSetnextvalue;
powerSet
Set of all subsets
warning the size of this set is exponential, 2 ^ this.size();
Example
let A = 123; let Apower = A;
cardinality
Returns the number of elements in the set.
Example
let A = 123; A //3
size
Returns the number of elements in the set.
Example
let A = 123; Asize //3