Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

A group-by function working with the built-in Array.reduce()

License

Notifications You must be signed in to change notification settings

EdJoPaTo/array-reduce-group-by

Repository files navigation

array-reduce-group-by

NPM Version node

A group-by function working with the built-in Array.reduce()

Deprecation Hint

Prefer ES2024 Object.groupBy() (supported since Node.js 21):

Object.groupBy(["Alpha", "Beta", "Animal"], (o) => o[0]);
//=> {A: ['Alpha', 'Animal'], B: ['Beta']}

Install

npm install array-reduce-group-by

Usage

import {arrayReduceGroupBy} from "array-reduce-group-by";

["Alpha", "Beta", "Animal"]
  .reduce(arrayReduceGroupBy((o) => o[0]), {});
//=> {A: ['Alpha', 'Animal'], B: ['Beta']}

Make sure not to forget the {} in the end!

API

arrayReduceGroupBy(keyFunc)

keyFunc

Type: (arrayElement) => string

Function to determine the key of a given array element

About

A group-by function working with the built-in Array.reduce()

Resources

License

Stars

Watchers

Forks