Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

merge-join-with

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

merge-join-with

Outer merge of two ordered arrays

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

Merge join with

This library exposes a method to perform full outer joins between ordered arrays in O(n).

Given two arrays

const populationById = [{id: 0, population: 1}, {id: 2, population: 2}]
const sizeById = [{id: 0, size: 1}, {id: 3, size: 4}]

We can join them to obtain:

const merge = [{id: 0, population: 1, size: 1}, {id: 2, population: 2}, {id: 3, size: 4}]

Usage

The method has four required parameters, the two arrays, the comparator function with with they where sorted and a function to join the elements

const mergeJoinWith = require('merge-join-with')
const comparisonFunction = (o1, o2) => o1.id - o2.id
const joinFunction = (o1, o2) => Object.assign({}, o1, o2)

const populationById = [{id: 0, population: 1}, {id: 2, population: 2}]
const sizeById = [{id: 0, size: 1}, {id: 3, size: 4}]

const merge = mergeJoinWith(populationById, sizeById, comparisonFunction, joinFunction)

Keywords

merge

FAQs

Package last updated on 31 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts