반응형

 

 

function solution(id_list, report, k) {
    let members = {};
    for (const r of report) {
        const [ reporter, reportee ] = r.split(" ");
        if (members[reportee]) {
            if (!members[reportee][1].includes(reporter)) {
                members[reportee][0]++;
                members[reportee][1].push(reporter);
                members[reportee][1] = [ ...new Set(members[reportee][1])];     
            }
        } else {
            members[reportee] = [1, [reporter]];
        }
    }
    let answer = new Array(id_list.length).fill(0);
    return Object.entries(members).reduce((acc, curr) => {
        const [key, value] = curr;
        if (value[0] >= k) {
            for (const reportee of value[1]) {
                const idx = id_list.indexOf(reportee);
                if (idx !== -1) {
                    answer[idx]++;
                }
            }   
        }
        return acc;
    }, answer);
}

 

 

 

반응형

+ Recent posts