프로그래머스 LEVEL 2(H-Index)

image

  • 사용 언어 : javascript

  • 해결 날짜 : 2022-09-13

  • 해결 방법 :
    • 내림차순 정렬 후 현재 인덱스(+1)가 값보다 커질 때 그 전 인덱스 반환
  • 회고 :
    • x
  • 코드

    function solution(citations) {
        citations.sort((a, b) => b - a);
        let hIndex = 0;
        for (const [index, citation] of citations.entries()) {
            if (index + 1 > citation) break;
            hIndex = index + 1;
        }
        return hIndex;
    }
    
  • 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges