API Reference

Runs a callback function on an array of items and returns a single object with the results as keys and count of each result as its value

function countsBy(things: any[], func: Function)

// Example:

const objs = [
        { a: 1, b: 1 },
        { a: 1, b: 1 },
        { a: 2, b: 1 },
        { a: 1, b: 1 },
        { a: 2, b: 2 },
        { a: 3, b: 1 },
      ]

const aPlusB = ({ a, b }: { a: number; b: number }) => a + b

countsBy(objs, aPlusB))

//=> 
    {
      "2": 3,
      "3": 1,
      "4": 2,
    }