Skip to main content
variable groupBy
import { groupBy } from "https://deno.land/x/30_seconds_of_typescript@v1.0.1/util.ts";

Groups the elements of an array based on the given function.

Use Array.prototype.map() to map the values of an array to a function or property name. Use Array.prototype.reduce() to create an object, where the keys are produced from the mapped results.

type MapFunc<T = any> = (val: T, index?: number, arr?: T[]) => T;

type

<T = any>(arr: T[], fn: MapFunc<T> | string) => unknown