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

이거 참고해서 공부를 좀 해야겠다 

 

 

 

+ Recent posts