Array filtering using buckets. Allows infinite buckets, bucket size limit, keeps input order and discards unmatched elements.
npm install bucket-filterReturns 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 bucketcondition. (Mixed)
// Note: This example uses ES6 syntaxvarfilter=require('bucket-filter')vardata=[{type: 1,title: 'foo-1-1'},// ...{type: 2,title: 'foo-2-1'},// ...]varbuckets=[// 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)// → []node benchmark.js10x 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)See the License file.