@extra-array/group-on
v2.7.8
Published
Breaks array keeping similar values together.
Downloads
308
Readme
Breaks array keeping similar values together. :running: :vhs: :package: :moon:
Alternatives: compare, map. This is part of package extra-array.
array.groupOn(x, [fn], [ths]);
// x: an array
// fn: map function (v, i, x)
// ths: this argument
const array = require('extra-array');
var x = [1, 2, 2, -2, -2, 4];
array.groupOn(x);
// [[1], [2, 2], [-2, -2], [4]]
array.groupOn(x, v => Math.abs(v));
// [[1], [2, 2, -2, -2], [4]]