Skip to main content
variable countBy
import { countBy } 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 and returns the count of elements in each group.

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

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