Answer to Question #296139 in HTML/JavaScript Web Application for chethan

Question #296139

Bunty Birthday

the goal of the code to get output using with DateMethods.


input

  • the input is containing single line an array birthdaysList.

output

  • the first line of output should be a number indicating the number of peoples born same day as Bunty
  • the first line of output should be a number indicating the number of peoples born same month as Bunty
  • the first line of output should be a number indicating the number of peoples born same year as Bunty


input1

['2000-05-13', 'June 7 2021','03/24/2000']

output1


1

2


input2

['Jan 26 2000','Dec 13 2001, 'Nov 18 2001']

output2




function readLine() {

 return inputString[currentLine++];

}


function main() {

 const birthdaysList = JSON.parse(readLine().replace(/'/g, '"'));

 const buntyBirthday = new Date("2000-06-13");


/* Please do not modify anything above this line */


 // Write your code here

  

}


1
Expert's answer
2022-02-13T09:45:06-0500
function readLine() {
    return inputString[currentLine++];
}
   
function main() {
    const birthdaysList = JSON.parse(readLine().replace(/'/g, '"'));
    const buntyBirthday = new Date("2000-06-13");
   
    /* Please do not modify anything above this line */
    let days = 0,
        months = 0,
        years = 0;

    birthdaysList.map(date => {
        if (new Date(date).getDate() == buntyBirthday.getDate()) days++
        if (new Date(date).getMonth() == buntyBirthday.getMonth()) months++
        if (new Date(date).getFullYear() == buntyBirthday.getFullYear()) years++
    })
   
    console.log(`Same days: ${days}\nSame months: ${months}\nSame years: ${years}`)

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS