https://github.com/jayrbolton/node-merge-sort
Implementation of merge sort for node.js
https://github.com/jayrbolton/node-merge-sort
Last synced: 2 months ago
JSON representation
Implementation of merge sort for node.js
- Host: GitHub
- URL: https://github.com/jayrbolton/node-merge-sort
- Owner: jayrbolton
- Created: 2017-12-29T18:45:12.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-29T18:47:35.000Z (over 7 years ago)
- Last Synced: 2025-02-13T09:36:09.894Z (3 months ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# node-merge-sort
> Merge sort implementation
Features
* O(n log n) performance
* Stable sort
* Generalized -- pass in your own comparison function## Usage
```js
var sort = require('@jayrbolton/merge-sort')var sorted = sort([5, 2, 4, 7, 1, 3, 2, 6])
// Or use a custom comparison function
sort([{x: 1}, {x: 2}], compare)
function compare (obj1, obj2) {
if (obj1.x < obj2.x) return -1
if (obj1.x > obj2.x) reuturn 1
else return 0
}
```outputs
```
[1, 2, 3, 4, 5, 6, 7]
```## Install
With [npm](https://npmjs.org/) installed, run
```
$ npm install @jayrbolton/merge-sort
```## Benchmarks
A simple benchmark in [/benchmark](/benchmark) shows merge sort to be marginally faster than the built-in sort function.
## License
MIT