0
Example:
const cores = [{id: 1, cor: 'azul'}, {id: 2, cor: 'azul'}, {id: 3, cor: 'azul'}, {id:4, cor: 'verde'}, {id: 5, cor: 'verde'}, {id: 6, cor: 'azul'}, {id: 7, cor: 'verde'}, {id: 8, cor: 'marrom'}, {id: 9, cor: 'marrom'}];
Final object to be returned when counting the items repeated accordingly:
const objeto = [{cor: 'azul', total: 3}, {cor: 'verde', total: 2}, {cor: 'Azul', total: 1}, {cor: verde, total: 1}, {cor: 'marrom', total: 2}];
I broke my head a lot with map and filter and this was the result:
cores.map(item => item.cor).map(value => { if(value !== cor) { cor = value; count = 1; return value; } else { count = ++count; cor = value; } return count; });
(9) ["azul", 2, 3, "verde", 2, "azul", "verde", "marrom", 2]
Notice that I got the value and the final result of those that have quantities larger than 1. After the blue color, the number 2 and 3 are the counts made by the map above and 3 and the total of blue of the first occurrence. After this the green that has 2 occurrences, then the blue and the green that has only 1 occurrence more I could not get them to return the integer value 1, then the brown that has 2 repeated occurrences. After this I tried to redo in other ways only flawed codes.
What codes have you tried to do? Edit your question so we can better know how to help you.
– Luiz Felipe