new initial commit (history rewritten)

This commit is contained in:
kuberwastaken
2026-03-31 16:25:52 +05:30
committed by Oleg Chirukhin
commit c1996f2e3b
1907 changed files with 514172 additions and 0 deletions

18
utils/objectGroupBy.ts Normal file
View File

@@ -0,0 +1,18 @@
/**
* https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.groupby
*/
export function objectGroupBy<T, K extends PropertyKey>(
items: Iterable<T>,
keySelector: (item: T, index: number) => K,
): Partial<Record<K, T[]>> {
const result = Object.create(null) as Partial<Record<K, T[]>>
let index = 0
for (const item of items) {
const key = keySelector(item, index++)
if (result[key] === undefined) {
result[key] = []
}
result[key].push(item)
}
return result
}