I have this array with hashes that I simplified to get smaller. My goal is to join with marca
of carros
to make a small report showing how much marca
is profiting based on compras
. Notice that "tag1" repeats 2 times and I do not want this 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 final result to be something like:
Marca: marca1
Vendas realizadas: 4
Valor total: 155000
--------
Marca: marca2
Vendas realizadas: 2
Valor total: 100000