flatten-overlapping-ranges

1.0.1 • Public • Published

flatten-overlapping-ranges

Flatten overlapping ranges into a sequence of sections.

---A---     ---C---
  -----B------
     --D--
-- --- -- --- -- -- -----
A  A   A         C  C
   B   B  B   B  B
       D  D

npm version build status ISC-licensed chat on gitter support me on Patreon

Installing

npm install flatten-overlapping-ranges

Usage

const flatten = require('flatten-overlapping-ranges')
 
const sections = flatten([
    ['A', 0, 7], // start a 0, length of 7
    ['B', 2, 12],
    ['D', 5, 5],
    ['C', 12, 7]
])
console.log(Array.from(sections))
[
    [2, ['A']], // length of 2
    [3, ['A', 'B']],
    [2, ['A', 'B', 'D']],
    [3, ['B', 'D']],
    [2, ['B']],
    [2, ['C', 'B']],
    [5, ['c']]
]

Instead of strings as range IDs, you can use anything a Map works with:

flatten([
    [{name: 'A'}, 0, 7],
    [{name: 'B'}, 2, 12]
])

Contributing

If you have a question or have difficulties using flatten-overlapping-ranges, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to the issues page.

Package Sidebar

Install

npm i flatten-overlapping-ranges

Weekly Downloads

31

Version

1.0.1

License

ISC

Unpacked Size

4.44 kB

Total Files

4

Last publish

Collaborators

  • derhuerst