https://school.programmers.co.kr/learn/courses/30/lessons/120882

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

function solution(score) {
    let answer = new Array(score.length).fill().map((v) => 0);
    let args = [];
    score.forEach((sc, index) => {
        let total = 0;
        sc.forEach((s) => {
            total += s;
        })
        args.push({arg : total/sc.length, index: index});
    });
    
    args.sort(function(a,b) {
        return b.arg - a.arg;
    });
    
   
    let tmp = [];
    let max = 0;
    let rank =1;
    while(true) {
        if(args.length === 0){
            break;
        }
        
        if(tmp.length === 0) {
            tmp.push(args.shift());
            max = tmp[0].arg;
        }
        
        args.forEach((a) => {
               if(max === a.arg) {
               tmp.push(a);
            } 
        });
        
        args = args.filter((a) => max !== a.arg);
            
        for(let i = 0 ; i < tmp.length ;i++) {
            answer[tmp[i].index] = rank;
        }
        
        rank += tmp.length;
        tmp = [];
        max = 0;
        
    }
        
    return answer;
}
728x90

+ Recent posts