본문 바로가기

프로그래머스/정렬

[정렬] 프로그래머스 'H-Index' - js

반응형

1. 문제

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

 

프로그래머스

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

programmers.co.kr

2. 코드

function solution(citations) {
    let answer = 0; 
    citations.sort((a,b) => b-a);
    
    while(true){
        if(citations.filter(el => el >= answer).length < answer) break;
        answer++;
    }
    
    return answer-1;
}

다른 방법)

이 로직은 h-index의 개념을 정확히 알고있어야만 이해할 수 있는 것 같다... 몇번을 봐도 시원하게 이해되지는 않는다 ㅠㅠㅠ

function solution(citations) {
    citations = citations.sort((a, b) => b - a);
    let i = 0;
    while (i + 1 <= citations[i]) i++;

    return i;
}

 

 

반응형