MCPcopy Create free account
hub / github.com/freecodexyz/free-code / countAndSortItems

Function countAndSortItems

src/utils/exampleCommands.ts:39–49  ·  view source on GitHub ↗
(items: string[], topN: number = 20)

Source from the content-addressed store, hash-verified

37 * sorted by count in descending order, formatted as a string.
38 */
39export function countAndSortItems(items: string[], topN: number = 20): string {
40 const counts = new Map<string, number>()
41 for (const item of items) {
42 counts.set(item, (counts.get(item) || 0) + 1)
43 }
44 return Array.from(counts.entries())
45 .sort((a, b) => b[1] - a[1])
46 .slice(0, topN)
47 .map(([item, count]) => `${count.toString().padStart(6)} ${item}`)
48 .join('\n')
49}
50
51/**
52 * Picks up to `want` basenames from a frequency-sorted list of paths,

Callers

nothing calls this directly

Calls 4

setMethod · 0.80
entriesMethod · 0.80
toStringMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected