export const createHashmapFromArr = <
D extends ObjectType,
K extends keyof D = StringNumberKeys<D>,
>(
data: D[],
refField: K,
): HashMapType<D, K> => {
return data.reduce((acc, item) => {
const refKey = item[refField]
if (typeof refKey === 'string' || typeof refKey === 'number') {
acc[refKey] = item
}
return acc
}, {} as HashMapType<D, K>)
}
Accepts array of objects and return the hash map object, in which the value of provided refField will be used as a key