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.
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]);
622 questions
979 answers
129 comments
53 users