function solution(today, terms, privacies) {
var answer = [];
const trimToday =new Date(today)
privacies.forEach((p,index)=>{
var now = new Date(p.slice(0,p.length-2))
var term = Number(terms.find((t)=>t[0]===p.slice(-1)).split(" ")[1])
var month = now.getMonth()
now.setMonth(month+term)
if(now<=trimToday){
answer.push(index+1);
}
})
return answer;
}
뭔가 지저분한 방식으로 풀었는데
나중에 다시 풀어봐야겠다
.slice() 말고 split을 쓰면 훨씬 간단하게 해결할 수 있었을텐데
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
구조 분해 할당 - JavaScript | MDN
구조 분해 할당 구문은 배열이나 객체의 속성을 해체하여 그 값을 개별 변수에 담을 수 있게 하는 JavaScript 표현식입니다.
developer.mozilla.org
이거 참고해서 공부를 좀 해야겠다
728x90
'코딩테스트' 카테고리의 다른 글
[프로그래머스] 같은 숫자는 싫어 js javascript (0) | 2024.05.09 |
---|---|
[프로그래머스 / dfs ] 타겟 넘버 js javascript (0) | 2024.05.07 |
[프로그래머스] 문자열 나누기 javascript js (0) | 2024.04.18 |
[프로그래머스] 체육복 javascript js (0) | 2024.04.18 |
[프로그래머스] 신규 아이디 추천 js javascript (0) | 2024.04.15 |