Working with an object array like:
const data = [
{count: 400, value: "Car Wash Drops"},
{count: 48, value: "Personal/Seeding"},
{count: 48, value: "Personal/Seeding"},
];
I am wanting to map
to an array with an additional identifier for duplicate values:
const expected = [
["Car Wash Drops", 400],
["Personal/Seeding (1)", 48],
["Personal/Seeding (2)", 48],
];
So far, I have a map function to map the values accordingly, but am unsure of how to proceed with appending the identifier only for duplicates.
data.map(d => [`${d.value}`, d.count]);
results in:
[
["Car Wash Drops", 400],
["Personal/Seeding", 48],
["Personal/Seeding", 48],
]
I have utilized the index as well with, but it adds the index on every value:
data.map((d, i) => [`${d.value} ${i}`, d.count]);
results in:
[
["Car Wash Drops (0)", 400],
["Personal/Seeding (1)", 48],
["Personal/Seeding (2)", 48],
]