I have array
const example = [{ day: 5, month: 1, key: 1 },{ day: 5, month: 1, key: 2 },{ day: 3, month: 3, key: 3 },{ day: 5, month: 1, key: 4 },{ day: 3, month: 3, key: 5 },{ day: 11, month: 4, key: 6 }];
how to check the elements of the day and month when the same ? if the year and month are repeated I would like the result return
{err:'the same',index:[0,1,2,3]}
My code not working.
const duplicates = Object.entries(array).reduce((acc, item, index) => {
if (acc[1].year === item[1].year && acc[1].month === item[1].month) {
return [
{
index:[acc[0],acc[1]],
err: "the same"
}
];
}
return acc;});