[JavaScript] 개인정보 수집 유효기간

ladiolus·2023년 5월 9일
0

programmers

목록 보기
6/25
post-thumbnail

문제풀이 📮

오늘 날짜로 파기해야 할 개인정보를 구하는 것이다.
모든 달은 28일까지 있다고 가정한 것을 유의해서 풀면 된다.

CODE

function solution(today, terms, privacies) {
    let deleteTerm = [];
    let termInfo = {};
    let [year, month, date] = today.split(".").map(Number);
    let todayCount = year * 12 * 28 + month * 28 + date;
    
    terms.forEach((term) => {
        let [type, period] = term.split(" ");
        termInfo[type] = Number(period);
    });
    
    privacies.forEach((privacy, i) => {
        let [day, type] = privacy.split(" ");
        day = day.split(".").map(Number);
        let dateCount = day[0] * 12 * 28 + day[1] * 28 + day[2] + termInfo[type] * 28;
        if (dateCount <= todayCount) deleteTerm.push(i + 1);
    });
    
    return deleteTerm;
}

0개의 댓글