const months = ['april','may','june','may','may','june'];
const countDuplicates = months.reduce((obj,month)=>{
if(obj[month] == undefined){
obj[month] = 1;
return obj;
}else{
obj[month]++;
return obj;
}
},{});
console.log(countDuplicates);//output:{april: 1, may: 3, june: 2}