2.0.0 • Published 8 years ago
balanced-comparative-selection v2.0.0
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-selectionUsage
var cs = require('comparative-selection');
cs.select( representations );API
Item
Type: Object
Properties
idstring ID of the itemabilitynumber the ability of the itemcomparedArray<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 testLinting
$ yarn lintLicense
GPL v3 © d-pac