https://codingdojang.com/scode/394
코딩도장
프로그래밍 문제풀이를 통해서 코딩 실력을 수련
codingdojang.com
정답코드
난이도 조절을 위해 윤년이나 평년을 고려하지 않음
function subdate(date) {
const 년 = parseInt(date.slice(0,4))
const 월 = parseInt(date.slice(4,6))
const 일 = parseInt(date.slice(6))
// console.log(년,월,일)
const 월별일 = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
let 일수 = 년 * 365 + 일
for (let i = 1; i < 월; i++) {
일수 += 월별일[i]
}
return 일수
}
function solution(a, b) {
return Math.abs(subdate(a) - subdate(b))
}
solution('20070301' , '20070515')