요약
풀이시간 : 42분 12초
문제 풀이
1. 1달을 28일로 계산
2. 만료일이 되는 순간 파기
3. split() 메서드의 활용
주의점
1. 타입 변환
고민
1. 변수명 짓기 참 어렵다
2. 시간이 걸려도 천천히 문제 읽기 (실수 줄이는게 관건)
3. 결국 알고리즘 문제는 1.데이터 전처리, 2.계산, 3.결과반환순임 각 파트 명확히하기
문제
[프로그래머스]개인정보 수집 유효기간
풀이
function solution(today, terms, privacies) {
const result = [];
const [yearT, monthT, dayT] = today.split(".").map(Number);
const totalDaysT = yearT * 12 * 28 + monthT * 28 + dayT;
const termMap = new Map(terms.map(term => {
const [type, duration] = term.split(" ")
return [type, Number(duration) * 28];
}));
for(const [i, privacy] of privacies.entries()){
const order = i + 1;
const [date, termType] = privacy.split(" ");
const [year, month, day] = date.split(".").map(Number);
const totalDaysP = year * 12 * 28 + month * 28 + day;
const expireDay = totalDaysP + termMap.get(termType);
expireDay <= totalDaysT && result.push(order);
}
return result;
}