math.set
Class to work with sets of real numbers.
Version
0.2.0
Install
npm install math.set
Usage
var MSet =var set = '(0, 2] U {6, 7, 8}'set // falseset // falseset // trueset // trueset // new MSet('(0, 7] U {8}')set // new MSet('(0, 2] U {6, 7} U [8, 9]')
API
Set
constructor(set)
Constructor creates an instance of Set class. it throws an error if set
is not SetCastable
Set#isEmpty()
It returns true or false if set is empty or not.
Example:
var MSet =var set = '[2, 4)'set // returns false
Set#contains(set)
It returns true
or false
if instance contains the set
passed by parameter. contains
throws an exception if set
is not SetCastable
Example:
var MSet =var set = '[1, 3) U [4, 8]'set // returns trueset // returns false
Set#union(...sets)
It returns a set that represents the union of sets
passed by parameter. It throws an error if some parameter is not SetCastable.
var MSet =var set = '[1, 3) U (3, 4]'set// returns new MSet('[1, 4] U {5} (6, 7)')
Set.union(...sets)
Set also has static method that calculates the union of sets in the same way as union
method.
var MSet =MSet// returns new MSet('[1, 4] U {5} (6, 7)')
SetCastable
A value is SetCastable if it is one of this list of types:
- instance of
Set
. - string that parses to set (
'[2, 5] U {4}'
,'[0, 5) U {-2, 8, 12.5}'
, etc). - IntervalCastable
- Array of IntervalCastable
Exported functions
rawSet(set)
It converts Set instance to array of data structure interval defined in math.interval-utils
package. It is posible to import this function thus:
var rawSet =
cast(set)
It converts SetCastable value to array of interval data structure interval defined in math.interval-utils
package. It is posible to import this function thus:
var rawSet =
LICENSE
MIT