I currently have this array:
const initialData = [
{
day: 1,
values: [
{
name: 'Roger',
score: 90,
},
{
name: 'Kevin',
score: 88,
},
{
name: 'Steve',
score: 80,
},
],
},
{
day: 2,
values: [
{
name: 'Roger',
score: 70,
},
{
name: 'Michael',
score: 88,
},
],
},
{
day: 3,
values: [
{
name: 'Steve',
score: 97,
},
],
},
];
which needs to be transformed into the following format:
const result = [
{
name: 'Roger',
scores: [90, 70, null],
},
{
name: 'Kevin',
scores: [88, null, null],
},
{
name: 'Steve',
scores: [80, null, 97],
},
{
name: 'Michael',
scores: [null, 88, null],
},
];
I've been attempting to accomplish this by utilizing map
on the array and creating a temporary holder array:
const holder = [];
initialData.map()
However, I haven't been successful in my attempts.