pair-filter
v1.0.0
Published
Returns items from an array of pairs that meet a predicate function
Downloads
3
Readme
pair-filter
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.