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 ] ]