我正在尝试使用下划线创建按位置分组的实体数组。
我有一个成对的数组,目前看起来像这样{ location: Location, data: T}[]
,我想将其变换成按{ location: Location, data: T[]}>[]
这样的位置分组。
我的第一个直觉是使用_.GroupBy
const entitiesMap = entities.map(e => ({ location: this.options.locationResolver(e), data: e})); this.locationEntitiesMap = _.groupBy(entitiesMap, entityPair => entityPair.location);
但是,当我这样做时,它会返回一个位置为Key的对象。我该如何返回分组数组?
我正在尝试使用下划线创建按位置分组的实体数组。我有一个成对的数组,当前看起来像这样{位置:位置,数据:T} []我想对其进行变换...
我会使用reduce