ACM준비/Programmers

개인정보 수집 유효기간

조규현15 2023. 5. 10. 21:04
반응형

https://school.programmers.co.kr/learn/courses/30/lessons/150370

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

주어진 데이터에서 규칙에 맞는 데이터를 찾는 과정이 필요합니다.

 

"현재 시간" 에서 "개인 정보의 시간" 의 차이가 유효 기간에 포함되는 지 판단합니다.

특별한 알고리즘이 필요하지 않으므로 N 시간에 해결할 수 있습니다.

* formatting 을 위해 Date 를 사용했습니다

 

function solution(today, terms, privacies) {
    var answer = [];

    var now = new Date(today);

    var termsMap = {};
    terms.forEach(element => {
        const [key, value] = element.split(' ');
        termsMap[key] = Number.parseInt(value);
    });

    privacies.forEach((element, index) => {
        var [date, term] = element.split(' ');
        var margin = new Date(date);

        var diffMonth = (now.getFullYear() - margin.getFullYear()) * 12 + (now.getMonth() - margin.getMonth());
        if (margin.getDate() - now.getDate() > 0) diffMonth -= 1;

        if (diffMonth >= termsMap[term]) {
            answer.push(index + 1);
        }
    });

    return answer;
}

* month 의 차이를 계산하는 과정에서 Date 가 아직 유효하다면 month 를 하나 빼주는 과정이 필요합니다.

반응형

'ACM준비 > Programmers' 카테고리의 다른 글

이모티콘 할인행사  (0) 2023.05.12
택배 배달과 수거하기  (0) 2023.05.11
올바른 괄호의 갯수  (0) 2023.01.09
쿠키 구입  (0) 2023.01.09
자동완성  (0) 2022.12.12