https://programmers.co.kr/learn/courses/30/lessons/92334
const lst=[1,4,2,3,5,5,5]
const set=new Set(lst)
lst=[...set]
const dictArr=Object.entries(dict)
const filtered=dictArr.filter((key)=>dict[key[0]]>=k)
const singo=Object.fromEntries(filtered)
const singo2=Object.keys(singo)
Object.entries(obj)
는 for...in
와 같은 순서로 주어진 객체 자체의 enumerable 속성 [key,value]쌍의 배열을 반환함
const obj = { foo: 'bar', baz: 42 };
console.log(Object.entries(obj)); // [ ['foo', 'bar'], ['baz', 42] ]
Object.fromEntries(iterable)
는 키값 쌍의 목록을 객체로 바꿈
const entries = new Map([
['foo', 'bar'],
['baz', 42]
]);
const obj = Object.fromEntries(entries);
console.log(obj); // Object { foo: "bar", baz: 42 }
function solution(id_list, report, k) {
var answer = {};
var dict={}
const set=new Set(report)
report=[...set]
for(let i=0;i<id_list.length;i+=1){
dict[id_list[i]]=0
answer[id_list[i]]=0
}
for(value of report){
tmp=value.split(" ")[1]
dict[tmp]+=1
}
const dictArr=Object.entries(dict)
const filtered=dictArr.filter((key)=>dict[key[0]]>=k)
const singo=Object.fromEntries(filtered)
const singo2=Object.keys(singo)
for(value of report){
[user,tmp]=value.split(" ")
if(singo2.includes(tmp)){
answer[user]+=1
}
}
return (Object.values(answer));
}
console.log(solution(["muzi", "frodo", "apeach", "neo"],["muzi frodo","apeach frodo","frodo neo","muzi neo","apeach muzi"],2))