# comparative-selection

> Comparative selection algorithm plugin for d-pac platform

Latest version **6.0.3** (published 2017-11-06) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install comparative-selection
pnpm add comparative-selection
yarn add comparative-selection
bun add comparative-selection
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.0.3 |
| Published | 2017-11-06 |
| First published | 2015-01-21 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+9 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | d-pac |
| Maintainers | creynders |
| Keywords | d-pac.plugin, d-pac, performance, assessment, comparative |

## Links

- npm: https://www.npmjs.com/package/comparative-selection
- Repository: https://github.com/d-pac/comparative-selection
- npm.io page: https://npm.io/package/comparative-selection

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) 4.1.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 6.0.3 (latest) — 2017-11-06
- 3.0.1 (next) — 2016-03-02
- 6.0.2 — 2017-11-06
- 6.0.1 — 2017-10-30
- 6.0.0 — 2017-10-19
- 5.0.0 — 2017-10-16
- 4.0.0 — 2017-10-11
- 3.0.3 — 2017-02-08
- 3.0.2 — 2016-11-30
- 3.0.0 — 2015-11-02
- 2.1.0 — 2015-10-01
- 2.0.2 — 2015-09-15
- 2.0.1 — 2015-09-15
- 2.0.0 — 2015-05-27
- 1.0.2 — 2015-04-13
- … 2 more at https://npm.io/package/comparative-selection/versions

## README

[![NPM version][npm-image]][npm-url]

> Comparative selection algorithm plugin for d-pac platform

Based on [NoMoreMarking's `cj` module](https://github.com/NoMoreMarking/cj).

## Description

The algorithm accepts a queue (Array) of items, then:

1.  pseudo-randomizes the items list
2.  sorts the list by the number of comparisons each item has been featured in
3.  retains the first item as 'selected'
4.  retains the next valid item as 'opponent':
    -   either, the next item in the (shuffled) list when 'selected' has no previous comparisons.
    -   or, the next item in the (shuffled) list 'selected' hasn't been compared to yet.
5.  returns both items

## Install

```sh
$ yarn add comparative-selection
```

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Item

Type: [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)

**Properties**

-   `id` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** ID of the item

### Comparison

Type: [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)

**Properties**

-   `a` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the ID of the "A" item
-   `b` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the ID of the "B" item

### select

Simple comparative selection algorithm

**Parameters**

-   `payload` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Payload object containing the relevant values
    -   `payload.items` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Item](#item)>** An array of [Item](#item)s
    -   `payload.comparisons` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Comparison](#comparison)>?** An array of [Comparison](#comparison)s

**Examples**

```javascript
const comparative = require('comparative-selection');

const pair = comparative.select([{id:"1"}, {id:"2"}, {id:"3"}, {id:"4"}]);
console.log('pair:', pair); // e.g.: {a: "2", b: "4"}
```

```javascript
const comparative = require('comparative-selection');

const pair = comparative.select([{id:"1"}, {id:"2"}, {id:"3"}, {id:"4"}], [{a:"2", b: "1"}]);
console.log('pair:', pair); // {a: "3", b: "4"}
```

Returns **[Comparison](#comparison)** the pair of item ID's to compare

## Development

### Testing

```sh
$ yarn test
```

### Linting

```sh
$ yarn lint
```

## License

GPL v3 © [d-pac](http://www.d-pac.be)

[npm-url]: https://npmjs.org/package/comparative-selection

[npm-image]: https://badge.fury.io/js/comparative-selection.svg

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