프로그래머스 Lv.1 신고결과 받기 문제 도전!
1차시도 -> 실패ㅠㅠ
function solution(id_list, report, k){
var answer = [];
// id_list[i] 번째 유저의 id를 변수명으로 지정하고, 해당 유저를 신고한 유저의 id를 값으로 push
for(let i =0; i < id_list.length; i++){
this[id_list[i]] = [];
this[id_list[i]+"_report"] = 0;
for (let j =0; j < report.length; j++){
let name = report[j].split(" ")[1];
if (id_list[i] === name){
this[id_list[i]].push(report[j].split(" ")[0]);
}
}
}
// id_list[i]번째 유저를 신고한 유저 id의 중복 값 제거
for(let i = 0; i < id_list.length; i++){
let new_arr = [];
if(this[id_list[i]].length >= k){
new_arr = this[id_list[i]].filter((element, index) => this[id_list[i]].indexOf(element) === index);
}
// 신고한 유저별 받을 mail 수 count
for(const element of new_arr){
for(const id of id_list){
if(element === id){
this[id+"_report"]++;
}
}
}
}
// 유저별 report 수를 result array에 push
for(const id of id_list){
answer.push(this[id+"_report"]);
}
return answer;
}
solution(["muzi", "frodo", "apeach", "neo"], ["muzi frodo","apeach frodo", "frodo neo","muzi neo","apeach muzi"], 2);
solution(["con", "ryan"], ["ryan con", "ryan con", "ryan con", "ryan con"], 6);
'TIL(today i learned) > 프로그래머스-코딩테스트' 카테고리의 다른 글
[연습문제] [Lv.1] 자릿수 더하기 (0) | 2022.11.11 |
---|---|
[연습문제][Lv.1] 약수의 합 (0) | 2022.11.11 |
[연습문제] [Lv.1] 평균 구하기 (0) | 2022.11.11 |
[연습문제] [Lv.1] 짝수와 홀수 (0) | 2022.11.11 |
[프로그래머스][Lv.1] 성격유형 검사하기 (0) | 2022.08.29 |