I got to count how many times the elements are repeating, but I dont know how remove the repeated elements and add the counter just leaving one, example:
const list = [
{name:'A', count: 3 },
{name:'B', count: 2 },
{name:'C', count: 1 }
]
const list = [
{ id:1, name:'A' },
{ id:2, name:'B' },
{ id:3, name:'A' },
{ id:4, name:'A' },
{ id:5, name:'B' },
{ id:6, name:'C' }
]
let current = null;
let counter = 0;
for (var i = 0; i < list.length; i++) {
if (list[i] != current) {
current = list[i];
counter = 1;
} else {
counter += 1;
}
}