1.0.0 • Published 5 years ago

pair-filter v1.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

pair-filter NPM version NPM monthly downloads

Returns items from an array of pairs that meet a predicate function

Install

Install with npm:

$ npm install --save pair-filter

Usage

const pairFilter = require("./index.js");

const pairs = [
    [1, 7],
    [2, 5],
    [4, 2],
    [3, 6],
    [6, 3],
    [7, 7]
];

pairFilter(pairs, (elem1, elem2) => elem1 >= elem2);
//[[4, 2], [6, 3], [7, 7]]

The first argument for pairFilter must be an array of 2-length arrays.

The second argument must be a function with between 2 and 4 arguments. The first 2 arguments are elements, the 3rd one is the index, and the 4th one is the original array.