Array filtering using buckets. Allows infinite buckets, bucket size limit, keeps input order and discards unmatched elements.
npm install bucket-filterArray filtering using buckets. Allows infinite buckets, bucket size limit, keeps input order and discards unmatched elements.
shell
npm install bucket-filter
`API
$3
Returns new _Array_ containing values filtered by buckets.
* input: Array input. (Array)
* buckets: Array of buckets: (Array)
* condition: Evaluates bucket selection. Return boolean. (Function)
* limit: Optional. Bucket size limit. (Number)
* this: Optional. Value of _this_ when executing each bucket condition. (Mixed)$3
`javascript
// Note: This example uses ES6 syntax
var filter = require('bucket-filter')var data = [
{ type: 1, title: 'foo-1-1' },
// ...
{ type: 2, title: 'foo-2-1' },
// ...
]
var buckets = [
// Include max 2 values where type is 1
{ condition: (i) => i.type === 1, limit: 2 },
// Include all values where type is 2
{ condition: (i) => i.type === 2 }
// All values not matching any condition will be dismissed
]
filter(data, buckets)
// → []
`Benchmark
`shell
node benchmark.js
`$3
`shell
10x array / 1x bucket x 787,188 ops/sec ±7.22% (75 runs sampled)
10x array / 2x buckets x 586,677 ops/sec ±0.67% (87 runs sampled)
10x array / 5x buckets x 255,597 ops/sec ±1.06% (89 runs sampled)
``