1
I have this hashed array that I’ve simplified to get smaller. My goal is to join by marca
of carros
to make a small report showing how much that marca
is making a profit based on compras
. Notice that "mark 1" repeats twice and I don’t want that to happen in the report.
carros = [
{
modelo: 'modelo1',
marca: 'marca1',
compras: [{preco: 20000}, {preco: 30000}]
},
{
modelo: 'modelo2',
marca: 'marca1',
compras: [{preco: 45000}, {preco: 60000}]
},
{
modelo: 'modelo3',
marca: 'marca2',
compras: [{preco: 77000}, {preco: 23000}]
}
]
I wanted the end result to be something like:
Marca: marca1
Vendas realizadas: 4
Valor total: 155000
--------
Marca: marca2
Vendas realizadas: 2
Valor total: 100000
I was able to adapt to my problem, thank you.
– Huskell