npm.io
2.7.8 • Published 4 years ago

@extra-array/group-on.min

Licence
MIT
Version
2.7.8
Deps
0
Size
8 kB
Vulns
0
Weekly
0

Breaks array keeping similar values together.

Alternatives: compare, map.
This is part of package extra-array.

This is browserified, minified version of @extra-array/group-on.
It is exported as global variable array_groupOn.
CDN: unpkg, jsDelivr.

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

references

Keywords