* EventTypeFilter UI working * Tidy + fix avatar + fix overflow * Component store * WIP - switchin to query filtering instead of state * Push working * Checkbox approach - weird conditional toggle for all bookings * WIP * the master query hook :O * useTypedQuery * Working typed query * Typed query hook * Add optional keys * safeParse query params * Add use callback * Fix re-renders * Remove local version of local query and use util branch * Working team filters! * working people filter! * Tidy up * NIT Co-authored-by: zomars <zomars@me.com>
19 lines
531 B
TypeScript
19 lines
531 B
TypeScript
type KeySelector<T> = (item: T) => string;
|
|
|
|
export function groupBy<T>(array: Iterable<T>, keySelector: KeySelector<T>): Record<string, T[]> {
|
|
return Array.from(array).reduce(
|
|
(acc: Record<string, T[]>, item: T) => {
|
|
const key = keySelector(item);
|
|
if (key in acc) {
|
|
// found key, push new item into existing array
|
|
acc[key].push(item);
|
|
} else {
|
|
// did not find key, create new array
|
|
acc[key] = [item];
|
|
}
|
|
return acc;
|
|
},
|
|
{} // start with empty object
|
|
);
|
|
}
|