Tweak feed display

This commit is contained in:
Jon Staab
2025-04-25 17:17:18 -07:00
parent 37c0491d71
commit b3e8d7a332
6 changed files with 37 additions and 20 deletions
+15
View File
@@ -628,6 +628,21 @@ export const groupBy = <T, K>(f: (x: T) => K, xs: T[]) => {
return r
}
/**
* Counts array elements by key function
* @param f - Function to generate group key
* @param xs - Array to count entries
* @returns Map of counts
*/
export const countBy = <T, K>(f: (x: T) => K, xs: T[]) => {
const r = new Map<K, number>()
for (const [k, items] of groupBy(f, xs)) {
r.set(k, items.length)
}
return r
}
/**
* Creates map from array using key function
* @param f - Function to generate key