https://school.programmers.co.kr/learn/courses/30/lessons/181838
정수 배열
date1
과date2
가 주어집니다. 두 배열은 각각 날짜를 나타내며[year, month, day]
꼴로 주어집니다. 각 배열에서year
는 연도를,month
는 월을,day
는 날짜를 나타냅니다.만약
date1
이date2
보다 앞서는 날짜라면 1을, 아니면 0을 return 하는 solution 함수를 완성해 주세요.
function solution(date1, date2) {
let [year1, month1, day1] = date1;
let [year2, month2, day2] = date2;
if(year1!==year2) return year1<year2? 1:0;
if(month1!==month2) return month1<month2?1:0;
if(day1!==day2) return day1< day2? 1:0;
return 0;
}
console.log(solution([2021, 12, 28],[2021, 12, 29])); //1
console.log(solution([1024, 10, 24],[1024, 10, 24])); //0
console.log(solution([2023, 1, 31], [2022, 12, 1])); //0
console.log(solution([2023, 5, 1], [2022, 4, 29])); //0
function solution(date1, date2) {
return new Date(date1)<new Date(date2)? 1: 0;
}
console.log(solution([2021, 12, 28],[2021, 12, 29])); //1
console.log(solution([1024, 10, 24],[1024, 10, 24])); //0
console.log(solution([2023, 1, 31], [2022, 12, 1])); //0
console.log(solution([2023, 5, 1], [2022, 4, 29])); //0