@extra-iterable/partition-on

Segregates values by similarity.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@extra-iterable/partition-on
512.3.03 years ago3 years agoMinified + gzip package size for @extra-iterable/partition-on in KB

Readme

Segregates values by similarity. :running: :vhs: :package: :moon: :ledger:
Alternatives: compare, map.
This is part of package extra-iterable.

iterable.partitionOn(x, [fn], [ths]);
// x:   an iterable
// fn:  map function (v, i, x)
// ths: this argument
// --> Map {key => values}

const iterable = require('extra-iterable');

var x = [1, 2, 3, 4];
iterable.partitionOn(x, v => v % 2 == 0);
// Map(2) { false => [ 1, 3 ], true => [ 2, 4 ] }

var x = [1, 2, 3, 4, 5];
iterable.partitionOn(x, v => v % 3);
// Map(3) { 1 => [ 1, 4 ], 2 => [ 2, 5 ], 0 => [ 3 ] }

references