settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Last month task in JavaScript

+1 vote

Write a JavaScript function/code/program that receives a date as array of strings containing day, month and year in that order. Your task is to print the last day of previous month (the month BEFORE the given date).

Check the examples to better understand the problem. The input comes as an array of numbers.

Examples:

Input:
[17, 3, 2002]

Output:
28


Input:
[13, 12, 2004]

Output:
30

The output should be a single number representing the last day of the previous month.

asked in JavaScript category by user hues

1 Answer

0 votes

Here is my last month code:

function solve([day, month, year]) {
    [day, month, year]=[day, month, year].map(Number);

    let date = new Date(year, month - 1, 0);
    console.log(date.getDate());
}

solve([13, 12, 2004]);

 

answered by user ak47seo
...