const map = new Map();
const ratio = [1, 1/2, 2/3, 3/4]
weights.sort((a,b)=>a-b)
for(x of weights) {
for(y of ratio) {
if(map.has(x*y)) answer+=map.get(x*y)
}
map.set(x, **(map.get(x)||0)+1)**
}
map.set(x, (map.get(x)||0)+1) <- 괄호에 주의하자
weights.sort((a,b)=>a-b)
for(x of weights) {
for(y of ratio) {
if(dic[x*y]) answer+=dic[x*y]
}
if(!dic[x]) dic[x]=1
else dic[x]++;
}
{} 사용법도 똑같이 key-value 쌍을 저장해주는 것이다.
어쩌면 더 간편할지도?