Socket
Book a DemoInstallSign in
Socket

balanced-comparative-selection

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

balanced-comparative-selection

Balanced comparative selection algorithm plugin for d-pac platform

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

NPM version

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 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

Keywords

d-pac.plugin

FAQs

Package last updated on 16 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts