I am trying to transform an array of objecst with keys: name and winRatio to another array of objects with a key of each unique name and value of an item in the winRatio array.
The purpose of this problem is to transform incomming data and reformat it into a chart realizing solution (Recharts, if you're interested)
Input
const data = [
{
name: 'Tyler',
winRatio: [1, 0.5, 0.6666666666666666],
},
{
name: 'Lizzie',
winRatio: [0, 0.5, 0.3333333333333333],
},
];
Output
const formatted = [
{
index: 0,
Tyler: 1,
Lizzie: 0,
},
{
index: 1,
Tyler: 0.5,
Lizzie: 0.5,
},
{
index: 2,
Tyler: 0.6666,
Lizzie: .333,
},
];
I thought about using map and reduce array functions, but I can't quite seem to wrap my mind around that.
Note Additionally, each object in the output should have an index value associated with the object that increments by one.
Note The length of the outputed array should be equal to the longest length of any winRatio array. For example, if the winRatio for 'Tyler' has 20 items, the output array should have 20 objects.