Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@antoniovdlc/reduce
Advanced tools
Custom reduce functions.
This package is distributed via npm:
npm install @antoniovdlc/reduce
Reducing arrays to a single value is a common operation in JavaScript. This library abstracts away some of the most common reduce operations.
You can use this library either as an ES module or a CommonJS package:
import { sum, average, groupBy } from "@antoniovdlc/reduce";
- or -
const { sum, average, groupBy } = require("@antoniovdlc/reduce");
All reduce functions can be used out of the box for computing single values as follows:
import { sum } from "@antoniovdlc/reduce";
const arr = [1, 2, 2, 13, 20, 4];
arr.reduce(sum); // 42
All reduce functions provide a .on("key")
function which allows to compute single values from arrays of objects by nested fields:
const arr = [
{ name: "Bob", age: 25 },
{ name: "Alice", age: 38 },
{ name: "Tom", age: 60 },
{ name: "Candice", age: 45 },
];
arr.reduce(average.on("age")); // 42
Note that if you are using TypeScript, you need to pass an initialization value:
arr.reduce(average.on("age"), 0); // 42
Here is a list of provided reduce functions:
Computes the sum of all the elements in an array.
Computes the average of all the elements in an array.
Generates an object from an array of objects, where the keys correspond to the values of the first argument, and the value corresponds to the object itself.
MIT
FAQs
Custom reduce functions.
The npm package @antoniovdlc/reduce receives a total of 2 weekly downloads. As such, @antoniovdlc/reduce popularity was classified as not popular.
We found that @antoniovdlc/reduce 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.