counting
创建一个包含项目出现次数的对象
110 bytes
since v12.1.0
使用方法
给定一个对象数组和一个身份回调函数来确定每个对象应该如何被识别。返回一个对象,其中键是回调返回的 id 值,每个值是一个整数,表示该 id 出现的次数。
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 }