// 添加一个辅助函数用于分组
const groupBy = <T>(
	array: T[],
	keyFn: (item: T) => string,
): Record<string, T[]> => {
	return array.reduce(
		(groups, item) => {
			const key = keyFn(item);
			if (!groups[key]) {
				groups[key] = [];
			}
			groups[key].push(item);
			return groups;
		},
		{} as Record<string, T[]>,
	);
};

export default groupBy;
