Tweak feed display
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user