Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mikolalysenko/binary-merge

2-way merge
https://github.com/mikolalysenko/binary-merge

Last synced: about 2 months ago
JSON representation

2-way merge

Awesome Lists containing this project

README

        

binary-merge
============
[Merges a pair of sorted arrays.](http://en.wikipedia.org/wiki/Merge_algorithm)

Use
===
First install via npm:

npm install binary-merge

Then you can use the algorithm as follows:

```javascript
var merge = require("binary-merge")

console.log(merge([1,3,7], [2,4,6]))

// Prints:
//
// 1,2,3,4,6,7
//
```

### `require("binary-merge")(a, b[, compare, result])`
The arguments are as follows:

* `a` a sorted array
* `b` again, a sorted array
* `compare` an optional comparison function
* `result` an optional array which gets the result of merging a and b. If not specified, a new array is allocated.

**Returns:** A sorted array.

**Time Complexity:** `O(a.length + b.length)`

Credits
=======
(c) 2013 Mikola Lysenko. MIT License