bunty birthday:
hey!!its bunty bithday
bunty was born on 13 June 2000 he is curious to know ow many people in is locality have their birthdays on the same day,month,year
given buntyBirthday in the prefilled code and a birthdayList as an input, write js program to find the number of people having their birthdays
on the same day
in the same month
in the same year
input:['2000-05-13' , 'June 7 2021' ,'03/24/2000']
output:
1
2
["2011-12-31","2011-02-14",'June 17 1998','12/02/1990','1995-10-23']
o/p:
1
let birthDay = new Date('June 13 2000');
let dates = ['2000-05-13' , 'June 7 2021' ,'03/24/2000'].map(x => new Date(x));
let result = {
days: 0,
months:0,
years:0
};
dates.forEach(x => {
if(x.getDate() === birthDay.getDate())
result.days++;
if(x.getMonth() === birthDay.getMonth())
result.months++;
if(x.getFullYear() === birthDay.getFullYear())
result.years++;
});
console.log(result.days);
console.log(result.months);
console.log(result.years);
Comments
Leave a comment