本文整理匯總了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]);
})