250x250
Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Archives
Today
Total
관리 메뉴

devlog_owen

[프로그래머스] H-Index 본문

algorithm/(js)프로그래머스

[프로그래머스] H-Index

developer_owen 2023. 11. 17. 23:39
728x90

문제

 

왜 이런걸 지표로 설정하신거죠? 


 

 

나의 풀이

function solution(citations) {

    let cita = citations.sort((a,b) => b-a)


    for(let i=0; i<cita.length; i++){
     let filteredCita = cita.filter(number => number >= i)
        if(cita[i] === filteredCita.length){
            return i+1
        }
    }
   
}

 

실패작이다. 왜 그런지 사실 잘 모르겠다. 

 

function solution(citations) {
    citations.sort((a, b) => b - a); // citations 배열을 내림차순으로 정렬

    let hIndex = 0; // 초기 h-index 값을 0으로 설정

   
    while (hIndex < citations.length && citations[hIndex] > hIndex) {
        hIndex++; // hIndex < citations.length: 범위설정, citations[hIndex] 값과 hIndex를 비교하여 h-index를 찾음
    }

    return hIndex; 
}

 

다시 풀어서 좀 더 깔끔하게 바꿈. 

 


 

다른 사람 풀이

 

본문1


 

회고

 

본문1


 

 

 

 

728x90