Comparative selection algorithm plugin for d-pac platform
Based on NoMoreMarking's cj
module.
Description
The algorithm accepts a queue (Array) of items, then:
- pseudo-randomizes the items list
- sorts the list by the number of comparisons each item has been featured in
- retains the first item as 'selected'
- 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.
- returns both items
Install
$ yarn add comparative-selection
API
Item
Type: Object
Properties
id
string ID of the item
Comparison
Type: Object
Properties
select
Simple comparative selection algorithm
Parameters
payload
Object Payload object containing the relevant valuespayload.items
Array<Item> An array of Itemspayload.comparisons
Array<Comparison>? An array of Comparisons
Examples
const comparative = ; const pair = comparative;console; // e.g.: {a: "2", b: "4"}
const comparative = ; const pair = comparative;console; // {a: "3", b: "4"}
Returns Comparison the pair of item ID's to compare
Development
Testing
$ yarn test
Linting
$ yarn lint
License
GPL v3 © d-pac