Suppose I have an unspecified number of arrays all with the same length. My goal is to merge them into a single array.
When I say merge, I mean combining the values from each array into the output array.
Is there a function called merge(...arrays)
that can achieve this?
Type Definition (potentially incorrect):
<T extends Array<U>, U>(...arr: T[]) => [...T][]
merge([A, B], [C, D])
→ [[A, C], [B, D]]
Examples:
merge([1, 2, 3], [10, 20, 30])
→[[1, 10], [2, 20], [3, 30]]
merge([1, 2, 3])
→[[1], [2], [3]]
→merge([1, "", {}], [17, { a: 1 }, "a"])
[[1, 17], ["", { a: 1 }], [{}, "a"]]
merge([])
→[]
UPDATE: Additionally, please provide a TypeScript Type definition for the function.