本文整理汇总了TypeScript中vs/base/common/collections.groupBy函数的典型用法代码示例。如果您正苦于以下问题:TypeScript groupBy函数的具体用法?TypeScript groupBy怎么用?TypeScript groupBy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了groupBy函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(markers: IMarker[]) {
super();
const byResource = groupBy(markers, r => r.resource.toString());
Object.keys(byResource).forEach(key => {
const markers = byResource[key];
const resource = markers[0].resource;
this.setResourceMarkers(resource, markers);
});
}
示例2: test
test('groupBy', () => {
const group1 = 'a', group2 = 'b';
const value1 = 1, value2 = 2, value3 = 3;
let source = [
{ key: group1, value: value1 },
{ key: group1, value: value2 },
{ key: group2, value: value3 },
];
let grouped = collections.groupBy(source, x => x.key);
// Group 1
assert.equal(grouped[group1].length, 2);
assert.equal(grouped[group1][0].value, value1);
assert.equal(grouped[group1][1].value, value2);
// Group 2
assert.equal(grouped[group2].length, 1);
assert.equal(grouped[group2][0].value, value3);
});
示例3: values
.then(plugins => {
const pluginsById = values(groupBy(plugins, p => p.id));
return pluginsById.map(p => p.sort((a, b) => semver.rcompare(a.version, b.version))[0]);
})