FrontEnd/프로그래머스
[JS] 신고 결과 받기
정_민_규
2023. 4. 17. 16:19
728x90
본인이 신고한 사람들을 저장할 객체와, 본인이 신고받은 수를 저장하는 객체를 만들어서 문제를 해결하였다.
function solution(id_list, report, k) {
const reportObj = {}
const reportCnt = {}
id_list.forEach(el => {
reportObj[el] = []
reportCnt[el] = 0
})
report.forEach(el => {
[a,b] = el.split(' ')
if(!reportObj[a].includes(b)) {
reportObj[a].push(b)
reportCnt[b]+=1
}
})
return id_list.map(el => reportObj[el].reduce((a,c) => reportCnt[c]>=k ? a+1 : a,0));
}
728x90