
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
array.prototype.groupby
Advanced tools
An ESnext spec-compliant `Array.prototype.groupBy` shim/polyfill/replacement that works as far down as ES3.
An ESnext spec-compliant Array.prototype.groupBy
shim/polyfill/replacement that works as far down as ES3.
This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the proposed spec.
Because Array.prototype.groupBy
depends on a receiver (the this
value), the main export takes the array to operate on as the first argument.
npm install --save array.prototype.groupby
var groupBy = require('array.prototype.groupby');
var assert = require('assert');
var arr = [0, 1, 2, 3, 4, 5];
var parity = function (x) { return x % 2 === 0 ? 'even' : 'odd'; };
var results = groupBy(arr, function (x, i, a) {
assert.equal(x, arr[i]);
assert.equal(a, arr);
return parity(x);
});
assert.deepEqual(results, {
__proto__: null,
even: [0, 2, 4],
odd: [1, 3, 5],
});
var groupBy = require('array.prototype.groupby');
var assert = require('assert');
/* when Array#groupBy is not present */
delete Array.prototype.groupBy;
var shimmed = groupBy.shim();
assert.equal(shimmed, groupBy.getPolyfill());
assert.deepEqual(arr.groupBy(parity), groupBy(arr, parity));
var groupBy = require('array.prototype.groupby');
var assert = require('assert');
/* when Array#groupBy is present */
var shimmed = groupBy.shim();
assert.equal(shimmed, Array.prototype.groupBy);
assert.deepEqual(arr.groupBy(parity), groupBy(arr, parity));
Simply clone the repo, npm install
, and run npm test
FAQs
An ESnext spec-compliant `Array.prototype.groupBy` shim/polyfill/replacement that works as far down as ES3.
We found that array.prototype.groupby demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.