Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

comparative-selection

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

comparative-selection

Comparative selection algorithm plugin for d-pac platform

latest
Source
npmnpm
Version
6.0.3
Version published
Maintainers
1
Created
Source

NPM version

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

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 comparative = require('comparative-selection');

const pair = comparative.select([{id:"1"}, {id:"2"}, {id:"3"}, {id:"4"}]);
console.log('pair:', pair); // e.g.: {a: "2", b: "4"}
const comparative = require('comparative-selection');

const pair = comparative.select([{id:"1"}, {id:"2"}, {id:"3"}, {id:"4"}], [{a:"2", b: "1"}]);
console.log('pair:', pair); // {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

Keywords

d-pac.plugin

FAQs

Package last updated on 06 Nov 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