/** * Группирует объекты по первой букве указанного свойства; нелитерные значения — под ключом nonLetterKey. * @param items - массив объектов * @param prop - свойство для группировки * @param nonLetterKey - ключ для нелитерных значений (по умолчанию 'POST') */ export function groupObjectsByFirstLetter( items: Array, prop: string, nonLetterKey = 'POST', ): Record> { return items.reduce((acc, item) => { const firstLetter = (item[prop as keyof T] as string).charAt(0).toUpperCase(); const key = /\p{L}/u.test(firstLetter) ? firstLetter : nonLetterKey; if (!acc[key]) { acc[key] = []; } acc[key].push(item); return acc; }, {} as Record>); }