balanced-comparative-selection

2.0.0 • Public • Published

NPM version

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

$ yarn add comparative-selection

Usage

var cs = require('comparative-selection');
 
cs.select( representations );

API

Item

Type: Object

Properties

  • id string ID of the item
  • ability number the ability of the item
  • compared Array<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

Properties

  • a string the ID of the "A" item
  • b string the ID of the "B" item

select

Simple comparative selection algorithm

Parameters

Examples

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 the pair of items to compare

Development

Testing

$ yarn test

Linting

$ yarn lint

License

GPL v3 © d-pac

Package Sidebar

Install

npm i balanced-comparative-selection

Weekly Downloads

3

Version

2.0.0

License

GPL-3.0

Last publish

Collaborators

  • creynders