Given an array of either 2d or 3d data. How can one create a function that converts the data to object of arrays, where the inner index maps to x, y or z depending on if the index is 0, 1 or 2 respectively. For example:
// 2d
const inputData2d = [
[-1, 4],
[3, 6],
[9, -8],
]
const outputData2d = {
x: [-1, 3, 9],
y: [4, 6, -8],
}
// 3d
const inputData3d = [
[-1, 4, 5],
[3, 6, 2],
[9, -8, 5],
]
const outputData3d = {
x: [-1, 3, 9],
y: [4, 6, -8],
z: [5, 2, 5],
}
The function should also be able to handle both 2d and 3d data, behaving as expected. I've explored using pipe and assoc but no luck as of yet.