Skip to content
/ rangelist Public

Implements list of ranges data sctructure to represent a non contiguous integer range

Notifications You must be signed in to change notification settings

vasc/rangelist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RangeList

Implements list of ranges data structure to represent a non contiguous range of numbers. This can be helpful to represent things like multiple time slots with a break in between or continuous spaces that get progressively occupied leaving openings in the middle.

This library allows you to manipulate ranges iteratively gettings consistent results, which can be tricky to do by hand.

Example

const { 
  addRange, 
  removeRange,  
  format
} = require('./lib/RangeList')

const emptyRange = [];
const oneToFive = addRange(emptyRange, [1, 5]);
// [[1, 5]]

const threeToFive = removeRange(oneToFive, [1, 3]);
// [[3, 5]]

const multipleSegments = addRange(threeToFive, [1, 2]);
// [[1, 2], [3, 5]]

format(multipleSegments);
// [1, 2) [3, 5)

Check the implementation for method documentation and the test file for more usage examples.

About

Implements list of ranges data sctructure to represent a non contiguous integer range

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published