-1
I would like to know how to count the same objects and return an array with the respective amounts of times it appeared.
I’m using several "for" to do this, and I don’t know how to do it with "map, reduce"
For example:
Entree:
array1 = [
{nome: joao, sobrenome: silva},
{nome: claudio, sobrenome: silva},
{nome: jose, sobrenome: oliveira},
{nome: joao, sobrenome: costa},
{nome: joao, sobrenome: silva}
]
Exit:
array2 = [
{nome: joao, sobrenome: silva, quantidade: 2},
{nome: joao, sobrenome: costa, quantidade: 1},
{nome: claudio, sobrenome: silva, quantidade: 1},
{nome: jose, sobrenome: oliveira, quantidade: 1}
]
The simplest way to do it is by using
for. There’s no reason to create additional complexity using reduce. You can see something like this reply. Moreover, the notation of his example is wrong.– Luiz Felipe