Basic operations on discrete intervals in JS
npm install interval-op0-dependencies library implemeting basic operations on discrete intervals where boundary conditions
reflect the intuitive expectations when dealing with availabilities.
``
// Union behaves like with closed intervals
[9 .. 12] U [12 .. 17] = [9 .. 17]
// Substraction behaves like with open intervals
[9 .. 17] - [15 .. 17] = [9 .. 15]
`$3
npm install interval-op
- The functions manipulate sets of intervals which are represented as arrays of intervals:
- [ [start1, end1], [start2, end2], ... ]
Examples:
`js
const { union, subtract } = require('interval-op')
console.log( union([ [9, 12], [12, 17] ]) ) // => [[9, 17]]
console.log( subtract([ [9, 17] ], [ [15, 17] ]) ) // => [[9, 15]]
`More examples can be found in test/test.js
$3
The library assumes that the elements used as interval boundaries
all have an order relation and can be compared with the relational
operators
>, <, >= and <=.
For example, it can be used with numbers or dates.To use it with a more complex object, you can read about
Abstract Relational Comparison
and Symbol.toPrimitive
See test/ComplexWithRelation.js for an example of
custom class implementing
Symbol.toPrimitive
$3
- Install dev dependencies with
npm install
*the library has no production dependencies, but uses standardJS
for linting/formatting*
- Run the test suite npm run test
- Run the linter with npx standard --fix`