Skip to content

counting

Creates an object with counts of occurrences of items

110 bytes

Usage

Given an array of objects and an identity callback function to determine how each object should be identified. Returns an object where the keys are the id values the callback returned and each value is an integer telling how many times that id occurred.

import * as _ from 'radashi'
const gods = [
{
name: 'Ra',
culture: 'egypt',
},
{
name: 'Zeus',
culture: 'greek',
},
{
name: 'Loki',
culture: 'greek',
},
]
_.counting(gods, g => g.culture) // => { egypt: 1, greek: 2 }