Array To Dict Function In TRPC Source Code
arrayToDict function in tRPC source code converts array to dictionary with index as key and value based on index. Simple yet effective solution after discussion in PR .
In this article, we analyze arrayToDict function found in tRPC source code. // https://github.com/trpc/trpc/pull/669 function arrayToDict(array: unknown[]) { const dict: Record<number, unknown> = {}; for (let index = 0; index < array.length; index++) { const element = array[index]; dict[index] = element; } return dict; } This function is straight forward. dict is an object initialized above the for loop. In this for loop, array[index] is assigned to element and dict is an object that array indices as keys and values being array items based on index. Although th...