balanced-comparative-selection
v2.0.0
Published
Balanced comparative selection algorithm plugin for d-pac platform
Downloads
11
Maintainers
Readme
Balanced comparative selection algorithm plugin for d-pac platform
Description
The algorithm accepts a queue (Array) of items, then:
- pseudo-randomizes the queue order
- sorts the queue by
compared.length
- retains the first item as 'selected'
- finds its position in the list sorted by ability
- 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
- 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 itemability
number the ability of the itemcompared
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
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