# balanced-comparative-selection

> Balanced comparative selection algorithm plugin for d-pac platform

Latest version **2.0.0** (published 2017-10-16) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install balanced-comparative-selection
pnpm add balanced-comparative-selection
yarn add balanced-comparative-selection
bun add balanced-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 | 2.0.0 |
| Published | 2017-10-16 |
| First published | 2017-10-12 |
| 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 | 0 |
| Author | d-pac |
| Maintainers | creynders |
| Keywords | d-pac.plugin, d-pac, performance, assessment, comparative |

## Links

- npm: https://www.npmjs.com/package/balanced-comparative-selection
- Repository: https://github.com/d-pac/balanced-comparative-selection
- npm.io page: https://npm.io/package/balanced-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

- 2.0.0 (latest) — 2017-10-16
- 1.0.0 — 2017-10-12

## README

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

> Balanced comparative selection algorithm plugin for d-pac platform

## Description

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

1.  pseudo-randomizes the queue order
2.  sorts the queue by `compared.length`
3.  retains the first item as 'selected'
4.  finds its position in the list sorted by ability
5.  retains the next valid item as 'opponent':
    -   from the other half of the ability sorted list
    -   giving preference to the items 'selected' has been compared with the least
6.  returns both items

## Install

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

## Usage

```js
var cs = require('comparative-selection');

cs.select( representations );
```

## 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
-   `ability` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the ability of the item
-   `compared` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>** An array containing id's of the items this item has been compared with.
    N.B. this _must_ contain duplicate ID's if the item has been compared multiple times with another 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)** The payload object
    -   `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

**Examples**

```javascript
const selected = cs.select([
  {
    id         : "3",
    compared    : [ "2", "4" ]
  },
  {
    id         : "2",
    compared    : [ "3" ]
  },
  {
    id         : "1",
    compared    : []
  },
  {
    id         : "4",
    compared    : [ "3", "5", "6" ]
  }
]);
console.log( selected );
// outputs:
// { a:"1", b:"2" }
```

Returns **[Comparison](#comparison)** the pair of items 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/balanced-comparative-selection

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

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