Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stoeffel/mergesort
O(n log n)
https://github.com/stoeffel/mergesort
Last synced: 12 days ago
JSON representation
O(n log n)
- Host: GitHub
- URL: https://github.com/stoeffel/mergesort
- Owner: stoeffel
- Created: 2015-01-04T20:16:20.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2020-10-01T08:59:46.000Z (about 4 years ago)
- Last Synced: 2024-10-13T02:12:48.922Z (28 days ago)
- Language: JavaScript
- Size: 151 KB
- Stars: 20
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
mergesort
================[![Build Status](https://travis-ci.org/stoeffel/mergesort.svg)](https://travis-ci.org/stoeffel/mergesort) [![npm version](https://badge.fury.io/js/divide-et-impera.svg)](http://badge.fury.io/js/divide-et-impera)
> [Mergesort](http://en.wikipedia.org/wiki/Merge_sort) with complexity O(n log n).Installation
------------`npm install divide-et-impera`
Usage
-----```js
var mergesort = require('divide-et-impera');// Sort an array
mergesort([3, 1, 2, 4, 2]); // => [1, 2, 2, 3, 4]var unsorted = [3, -2, 5];
var sorted = mergesort(unsorted);
// unsorted => [3, -2, 5]
// sorted => [-2, 3, 5]// Use a custom comparator
function desc(a, b) {
return b - a;
}
mergesort([3, 1, 2, 4, 2], desc); // => [4, 3, 2, 2, 1]// Use with compare.js
var desc = require('compare.js/desc');
var date = require('compare.js/date');
var dates = ['01.01.2014', '30.03.2015', '18.01.2015'];mergesort(dates, desc(date('DD.MM.YYYY'))); // => ['30.03.2015', '18.01.2015', '01.01.2014']
```