Giter VIP home page Giter VIP logo

weighted-interval-merge's Introduction

Weighted interval merge

This library offers a default interval merge along with the ability to add a weight to each interval which will be used to resolve overlaps. If no weight is given or all weights are the same it will produce a standard interval merge, going from left to right.

The operation makes a copy of the input array, the original array and it's elements are unaltered. Any extra properties are preserved on the copy.

The method expects an input array with elements matching the following signature, only start and end properties are required. offsetStart and index default to 0.

Indexes are normalized back to 1, so three intervals with indexes 3, 5 and 10 will be normalized to 1, 2, 3.

Installation

  npm install --save weighted-interval-merge

Code example

import { weightedIntervalMerge } from "weighted-interval-merge";

const intervals = [
  { id: 1, start: 0, offsetStart: 1, end: 10, index: 0 },
  { id: 2, start: 2, end: 7, index: 1 },
  { id: 3, start: 4, end: 5, index: 2 }
];

const merged = weightedIntervalMerge(intervals);
console.log(merged);

// [
//   { id: 1, start: 0, offsetStart: 1, end: 2, index: 1 },
//   { id: 2, start: 2, end: 4, index: 2, offsetStart: 0 },
//   { id: 3, start: 4, end: 5, index: 3, offsetStart: 0 },
//   { id: 2, start: 2, end: 7, index: 2, offsetStart: 3 },
//   { id: 1, start: 0, offsetStart: 7, end: 10, index: 1 }
// ];

weighted-interval-merge's People

Contributors

idicious avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.