# async-merge-sort

> Efficiently sort an array with an asynchronous comparison function. Suitable for sorts driven by prompting the user for each comparison, for instance.

Latest version **0.1.3** (published 2015-12-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install async-merge-sort
pnpm add async-merge-sort
yarn add async-merge-sort
bun add async-merge-sort
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2015-12-31 |
| First published | 2015-07-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | P'unk Avenue LLC |
| Maintainers | boutell |
| Keywords | async, merge, sort, asynchronous |

## Links

- npm: https://www.npmjs.com/package/async-merge-sort
- Repository: https://github.com/punkave/async-merge-sort
- Issues: https://github.com/punkave/async-merge-sort/issues
- npm.io page: https://npm.io/package/async-merge-sort

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 0.1.3 (latest) — 2015-12-31
- 0.1.2 — 2015-07-01
- 0.1.1 — 2015-07-01
- 0.1.0 — 2015-07-01

## README

# async-merge-sort

<a href="http://apostrophenow.org/"><img src="https://raw.github.com/punkave/async-merge-sort/master/logos/logo-box-madefor.png" align="right" /></a>

`async-merge-sort` can efficiently sort an array with an asynchronous comparison function. It is suitable for sorts driven by prompting the user for each comparison, or any other situation where you cannot reduce each item to a "score" that can be compared synchronously.

## How to use

```javascript
    // in-browser example, with browserify and jQuery.
    // Can also be used server side via npm install

    var asyncMergeSort = require('async-merge-sort');

    var $a = $('[data-a]');
    var $b = $('[data-b]');
    return asyncMergeSort(items, function(a, b, callback) {
      // compare the items by prompting the user to click
      // one or the other. We'll re-label two elements in
      // the page and wait to see which is clicked
      $a.text(a);
      $b.text(b);
      $a.off('click');
      $b.off('click');
      $a.on('click', function() {
        return callback(null, -1);
      });
      $b.on('click', function() {
        return callback(null, 1);
      });
    }, function(err, sorted) {
      if (err) {
        // Comparison function reported an error
        alert('Oh dear, an error occurred.');
      }
      // log the sorted items
      console.log(sorted);
    });
```

## Limitations

Since the overwhelming majority of the time presumably is spent waiting around for the comparison function to invoke its callback, this module is not written with raw speed in mind. It's also possible to create fewer arrays. This was simply the most readable version of the algorithm.

## Browser Compatibility

No new-wave JavaScript features are required. Expected to work in all browsers going back quite a long way.

## Changelog

0.1.2: tests don't require lodash either. No other changes.

0.1.1: removed dependency on lodash. No longer imports any other modules.

0.1.0: initial version. Passing unit tests.

## About P'unk Avenue and Apostrophe

`async-merge-sort` was created at [P'unk Avenue](http://punkave.com) for use in projects based on Apostrophe, an open-source content management system built on node.js. If you like `async-merge-sort` you should definitely [check out apostrophenow.org](http://apostrophenow.org). Also be sure to visit us on [github](http://github.com/punkave).

## Support

Feel free to open issues on [github](http://github.com/punkave/async-merge-sort).

<a href="http://punkave.com/"><img src="https://raw.github.com/punkave/async-merge-sort/master/logos/logo-box-builtby.png" /></a>

---
_Source: https://npm.io/package/async-merge-sort · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
