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
import _
_from'radashi'
const
constgods: {
name:string;
culture:string;
}[]
gods= [
{
name: string
name: 'Ra',
culture: string
culture: 'egypt',
},
{
name: string
name: 'Zeus',
culture: string
culture: 'greek',
},
{
name: string
name: 'Loki',
culture: string
culture: 'greek',
},
]
const
constcountingByCulture:Record<string, number>
countingByCulture=
import _
_.
counting<{
name:string;
culture:string;
}, string>(array:readonly {
name:string;
culture:string;
}[], identity: (item: {
name:string;
culture:string;
}) =>string):Record<string, number>
export counting
Counts the occurrences of each unique value returned by the identity
function when applied to each item in the array.