[
{
name: 'lala',
foo: [
{
channel: 0,
scores: [
{
score: 123
}
],
},
{
channel: 1,
scores: [
{
score: 120
}
],
},
]
},
{
name: 'lolo',
bar: [
{
channel: 0,
scores: [
{
score: 1277
}
],
},
{
channel: 1,
scores: [
{
score: -111
}
],
}
]
},
{
name: 'lele',
baz: [
{
channel: 0,
scores: [
{
score: 1
}
],
},
{
channel: 1,
scores: [
{
score: -3
}
],
}
]
}
]
[
{
channel: 0,
name: 'lolo',
score: 1277,
},
{
channel: 1,
name: 'lala',
score: 120,
}
]
Object.values(arr.reduce((acc, { name, ...n }) => (
Object.values(n).find(Array.isArray)?.forEach(({ scores, channel }) =>
scores.forEach(({ score }) =>
(acc[channel]?.score > score) || (acc[channel] = { channel, name, score })
)
),
acc
), {}))