Array Reducing Utilities

2.1.0 · abandoned · verified Sun Apr 19

The `arrayreduce` package, currently at version 2.1.0, provides a small collection of pre-built, reusable reducer functions designed to simplify common array reduction patterns when used with JavaScript's native `Array.prototype.reduce` method. These utilities include functions for tasks such as concatenating nested arrays, performing logical AND/OR operations across array elements, and transforming an array of objects into an indexed object based on a specified attribute. Due to its last update approximately five years ago, the package is considered abandoned, lacks active maintenance, and does not provide native ES module (ESM) support or TypeScript type definitions. It targets older Node.js environments (>=4.0.0), making it less ideal for contemporary JavaScript projects without appropriate transpilation or CJS-to-ESM bridging solutions.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing the module and using `indexByAttr` to create an object indexed by ID, along with a simple boolean reduction.

const arrayreduce = require('arrayreduce');

// Get a reducer function to index an array of objects by an attribute.
const indexById = arrayreduce.indexByAttr('id');

// Sample data
const data = [
    {id: 101, name: 'Alice', age: 30},
    {id: 102, name: 'Bob', age: 24},
    {id: 103, name: 'Charlie', age: 35}
];

// Execute the reduction to create an indexed object
const indexedResult = data.reduce(indexById, {});

console.log(indexedResult);
/*
Output:
{
  '101': { id: 101, name: 'Alice', age: 30 },
  '102': { id: 102, name: 'Bob', age: 24 },
  '103': { id: 103, name: 'Charlie', age: 35 }
}
*/

// Another example: Boolean AND reduction
const booleanAndReducer = arrayreduce.booleanAnd();
const andResult = [true, false, true].reduce(booleanAndReducer, true);
console.log('Boolean AND result:', andResult); // -> Boolean AND result: false

view raw JSON →