@extra-iterable/group-on

Keeps similar values together and in order.

Downloads in past

Stats

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

Readme

Keeps similar values together and in order. :running: :vhs: :package: :moon: :ledger:
Alternatives: compare, map.
This is part of package extra-iterable.

iterable.groupOn(x, [fn], [ths]);
// x:   an iterable
// fn:  map function (v, i, x)
// ths: this argument

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

var x = [1, 2, 2, -2, -2, 4];
[...iterable.groupOn(x)];
// [ [ 1 ], [ 2, 2 ], [ -2, -2 ], [ 4 ] ]

[...iterable.groupOn(x, v => Math.abs(v))];
// [ [ 1 ], [ 2, 2, -2, -2 ], [ 4 ] ]

references