Untitled
unknown
plain_text
4 years ago
414 B
11
Indexable
const result = data.reduce((acc, curr) => {
// [curr.category.name]
if (!curr.price) return acc;
if (acc[curr.category]) {
acc[curr.category] += Number(curr.price);
} else {
acc[curr.category] = Number(curr.price);
}
return acc;
},{});
const gastos = Object.entries(result);
const flatted = gastos.flatMap(el => {
return {[el[0]]: el[1]};
});
console.log(flatted);Editor is loading...