combine-lists

WebJar for combine-lists

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

combine-lists
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

combine-lists
WebJar for combine-lists
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/sjelin/combine-lists

Download combine-lists

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/combine-lists/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>combine-lists</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/combine-lists/
implementation 'org.webjars.npm:combine-lists:1.0.1'
// https://jarcasting.com/artifacts/org.webjars.npm/combine-lists/
implementation ("org.webjars.npm:combine-lists:1.0.1")
'org.webjars.npm:combine-lists:jar:1.0.1'
<dependency org="org.webjars.npm" name="combine-lists" rev="1.0.1">
  <artifact name="combine-lists" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='combine-lists', version='1.0.1')
)
libraryDependencies += "org.webjars.npm" % "combine-lists" % "1.0.1"
[org.webjars.npm/combine-lists "1.0.1"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm : lodash jar [4.5.0,5)

Project Modules

There are no modules declared in this project.

This tool merges two lists, removing duplicates, and doing everything possible to maintain the order of the two lists.

This tool guarantees that the order of the first list is preserved (that is, if x comes before y in the first list, x comes before y in the returned list) and tries not to undo the order of the second list, though sometimes it is unavoidable.

For example, if we have list1 = [1, 2, 4] and list2 = [2, 1, 3, 4], then the merged list would be [1, 2, 3, 4], since that preserves the order of list1 while doing the best job possible of preserving the order of list2.

A case like list1 = [1, 3], list2 = [3, 2, 1] is more complicated. It's not clear what the best merged list is, but it's probably either [2, 1, 3] or [1, 3, 2].

In general, it's not totally clear what the "best" merged list is, but there are some basic properties that anyone would expect:

  • Since the order of list1 is preserved, the merged list will look like the first list with the elements exclusive to the second inserted in betweeen
  • If list2[i] is not in list1, and it is possible to insert list2[i] into list1 without contradicting the order of list2, then it should be inserted in such a way

This tool is very slow, crossing the 100ms mark with lists around 150 in length, and growing at a rate of O(list2.length*list2.length*(list1.length + list2.length)) from there.

Installation / Usage

Install with

npm install combine-lists

Use like so:

var combineLists = require('combine-lists');
combineLists([1, 2], [2, 3]); // [1, 2, 3]

Versions

Version
1.0.1