本文整理汇总了TypeScript中lodash.countBy函数的典型用法代码示例。如果您正苦于以下问题:TypeScript countBy函数的具体用法?TypeScript countBy怎么用?TypeScript countBy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了countBy函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: collateEntityIds
private collateEntityIds(entityType: string, nonUniqueEntityIds: string[]): ICollatedIdGroup[] {
const entityIds = uniq(nonUniqueEntityIds);
const entityIdCounts = countBy(nonUniqueEntityIds);
const baseUrlLength = `${SETTINGS.gateUrl}/tags?entityType=${entityType}&entityIds=`.length;
const maxIdGroupLength = get(SETTINGS, 'entityTags.maxUrlLength', 4000) - baseUrlLength;
const idGroups: ICollatedIdGroup[] = [];
const joinedEntityIds = entityIds.join(',');
const maxGroupSize = 100;
if (joinedEntityIds.length > maxIdGroupLength) {
let index = 0,
currentLength = 0;
const currentGroup: string[] = [];
while (index < entityIds.length) {
if (currentLength + entityIds[index].length + 1 > maxIdGroupLength || currentGroup.length === maxGroupSize) {
idGroups.push(this.makeIdGroup(currentGroup, entityIdCounts));
currentGroup.length = 0;
currentLength = 0;
}
currentGroup.push(entityIds[index]);
currentLength += entityIds[index].length + 1;
index++;
}
if (currentGroup.length) {
idGroups.push(this.makeIdGroup(currentGroup, entityIdCounts));
}
} else {
idGroups.push(this.makeIdGroup(entityIds, entityIdCounts));
}
return idGroups;
}
开发者ID:jcwest,项目名称:deck,代码行数:32,代码来源:entityTags.read.service.ts
示例2: unmatch
export function unmatch(orbs: Orb[][], match: number[][]): Orb[][] {
let intersections: number[][] = [];
// it is a simple match if all of the coords have only 1 rowCoord or 1 colCoord
let [rowCoords, colCoords] = _.zip(...match);
let isSimpleMatch = _.uniq(rowCoords).length === 1 || _.uniq(colCoords).length === 1;
if (isSimpleMatch) {
// finds the median orb in the match
let median = Math.floor(match.length / 2);
let [midRow, midCol] = match[median];
// Checks for a side-by-side match, which could cause and endless loop.
// In that case, the skipToRandom argument in _unmatch is triggered.
let midNeighbors: Orb[];
if (_.uniq(rowCoords).length === 1) {
midNeighbors = [orbs[midRow][midCol - 1], orbs[midRow][midCol + 1]];
} else {
midNeighbors = [orbs[midRow - 1][midCol], orbs[midRow + 1][midCol]];
}
let isSideBySideMatch = _.includes(midNeighbors, orbs[midRow][midCol]);
orbs = _unmatch(orbs, midRow, midCol, match, isSideBySideMatch);
} else {
// collects which rows and columns have matches in them
let matchRows: number[] = [];
let matchCols: number[] = [];
_.each(_.countBy(rowCoords), (v, k) => {
if (v > 2) {
matchRows.push(_.toInteger(k));
};
});
_.each(_.countBy(colCoords), (v, k) => {
if (v > 2) {
matchCols.push(_.toInteger(k));
};
});
// if a coordinate is in a row match and a column match, it is an intersection
_.each(match, coords => {
if (_.includes(matchRows, coords[0]) && _.includes(matchCols, coords[1])) {
intersections.push(coords);
};
});
// chooses a random intersection to unmatch
let [row, col] = _.sample(intersections);
_unmatch(orbs, row, col, match);
};
return orbs;
};
开发者ID:PlaytestersKitchen,项目名称:match-three-js,代码行数:47,代码来源:orbs.ts
示例3: textForHtml
textForHtml(boundVariableLists: string[][]) {
const name = boundVariableLists[this.level][this.index];
if (_.countBy(_.flattenDeep(boundVariableLists))[name] > 1) { // Disambiguate variables that appear multiple times in scope
return this.serialize()
} else {
return name;
}
}
开发者ID:reavowed,项目名称:prover,代码行数:8,代码来源:Expression.ts
示例4: reject
redisClient.hvals('users', (err, replies) => {
if (err) {
console.error(err);
reject(err);
}
const counts = countBy(replies);
resolve(counts);
});
开发者ID:odetown,项目名称:golfdraft,代码行数:9,代码来源:userAccess.ts
示例5: createApmTelementry
export function createApmTelementry(
agentNames: string[] = []
): SavedObjectAttributes {
const validAgentNames = agentNames.filter(isAgentName);
return {
has_any_services: validAgentNames.length > 0,
services_per_agent: countBy(validAgentNames)
};
}
开发者ID:elastic,项目名称:kibana,代码行数:9,代码来源:apm_telemetry.ts
示例6: makeRoomForPostmaster
export async function makeRoomForPostmaster(
store: DimStore,
toaster,
bucketsService: () => Promise<InventoryBuckets>
): Promise<void> {
const buckets = await bucketsService();
const postmasterItems: DimItem[] = _.flatMap(
buckets.byCategory.Postmaster,
(bucket: InventoryBucket) => store.buckets[bucket.id]
);
const postmasterItemCountsByType = _.countBy(postmasterItems, (i) => i.bucket.id);
// If any category is full, we'll move enough aside
const itemsToMove: DimItem[] = [];
_.each(postmasterItemCountsByType, (count, bucket) => {
if (count > 0 && store.buckets[bucket].length > 0) {
const items: DimItem[] = store.buckets[bucket];
const capacity = store.capacityForItem(items[0]);
const numNeededToMove = Math.max(0, count + items.length - capacity);
if (numNeededToMove > 0) {
// We'll move the lowest-value item to the vault.
const candidates = _.sortBy(items.filter((i) => !i.equipped && !i.notransfer), (i) => {
let value: number = {
Common: 0,
Uncommon: 1,
Rare: 2,
Legendary: 3,
Exotic: 4
}[i.tier];
// And low-stat
if (i.primStat) {
value += i.primStat.value / 1000;
}
return value;
});
itemsToMove.push(..._.take(candidates, numNeededToMove));
}
}
});
// TODO: it'd be nice if this were a loadout option
try {
await moveItemsToVault(store.getStoresService(), store, itemsToMove, dimItemService);
toaster.pop(
'success',
t('Loadouts.MakeRoom'),
t('Loadouts.MakeRoomDone', {
count: postmasterItems.length,
movedNum: itemsToMove.length,
store: store.name,
context: store.gender
})
);
} catch (e) {
toaster.pop('error', t('Loadouts.MakeRoom'), t('Loadouts.MakeRoomError', { error: e.message }));
throw e;
}
}
开发者ID:w1cked,项目名称:DIM,代码行数:56,代码来源:postmaster.ts
示例7: return
_.filter(polyhedron.faces, face => {
const faceCounts = _.countBy(
face.vertexAdjacentFaces().filter(f => !f.equals(face)),
'numSides',
);
return (
_.isEqual(faceCounts, { '4': face.numSides }) ||
_.isEqual(faceCounts, { '3': 2 * face.numSides })
);
}),
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:10,代码来源:prismUtils.ts
示例8: createApmTelementry
export function createApmTelementry(
agentNames: AgentName[] = []
): ApmTelemetry {
const validAgentNames = agentNames.filter(agentName =>
Object.values(AgentName).includes(agentName)
);
return {
has_any_services: validAgentNames.length > 0,
services_per_agent: countBy(validAgentNames)
};
}
开发者ID:gingerwizard,项目名称:kibana,代码行数:11,代码来源:apm_telemetry.ts
示例9: mapValues
return mapValues(visTypes, curr => {
const total = curr.length;
const spacesBreakdown = countBy(curr, 'space');
const spaceCounts: number[] = _.values(spacesBreakdown);
return {
total,
spaces_min: _.min(spaceCounts),
spaces_max: _.max(spaceCounts),
spaces_avg: total / spaceCounts.length,
};
});
开发者ID:elastic,项目名称:kibana,代码行数:12,代码来源:task_runner.ts
示例10: it
it("returns calendar rows: empty", () => {
const eventData: EventData = {
start_time: "2017-12-20T01:02:00.000Z",
end_time: "2019-12-20T01:05:00.000Z",
repeat: 100,
time_unit: "yearly"
};
const testTime = moment("2017-12-30T01:00:00.000Z");
const calendar = mapResourcesToCalendar(
fakeSeqFEResources(eventData).index, testTime);
const dayOneItems = calendar.getAll()[0].items;
expect(countBy(dayOneItems, "heading")).toEqual({ "*Empty*": 1 });
});
开发者ID:RickCarlino,项目名称:farmbot-web-app,代码行数:13,代码来源:map_state_to_props_test.ts
注:本文中的lodash.countBy函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论