I have the following array
array = [{
key: '2001',
values: [
{ id : '123a', points: 3, hours: 3 },
{ id : '123a', points: 4, hours: 2 },
{ id : '4444', points: 3, hours: 2 },
{ id : '4444', points: 3, hours: 5 },
]
}, {
key: '2002',
values: [
{ id : '12d3a', points: 5, hours: 2 },
{ id : '12w3a', points: 3, hours: 3 },
]
}]
With this function
const {map, evolve, pipe, groupBy, prop, pluck, sum, toPairs, zipObj} = R;
const a = map(evolve({
values: pipe(
groupBy(prop('id')),
map(pluck('hours')),
map(sum),
toPairs,
map(zipObj(['id', 'hours']))
)
}))
I gathered all "hours" for each id for each key (2001, 2002..)
array = [{
key: '2001',
values: [
{ id : '123a', hours: 5 },
{ id : '4444', hours: 7 }....
Now I want to add another value to each object, called sum. var sum = (points*hours)/(sum(hours)).
Any idea how can i do this? I've tried to change const a but is not working and I don't know if ramda can to this operation. Maybe an alternative?
array = [{
key: '2001',
values: [
{ id : '123a', hours: 5, sum: 3.4 },
{ id : '4444', hours: 7, sum: 3 }....