- Related Questions & Answers
- H-Index in C++
- H-Index II in C++
- Program to find H-Index from a list of citations in C++
- Calculating least common of a range JavaScript
- Calculating the weight of a string in JavaScript
- Calculating average of a sliding window in JavaScript
- Calculating resistance of n devices - JavaScript
- Calculating median of an array JavaScript
- Calculating average of an array in JavaScript
- Calculating median of an array in JavaScript
- Calculating excluded average - JavaScript
- Calculating the sum of digits of factorial JavaScript
- Calculating the LCM of multiple numbers in JavaScript
- Calculating a number from its factorial in JavaScript
- Calculating 1s in binary representation of numbers in JavaScript

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have an array of positive integers that represents the number of citations a particular researcher has conducted over a period of time.

We are required to write a JavaScript function that takes in one such array and the function should find the h-index of that researcher based on the citations data represented by the array.

Consider a researcher who performed N number of citations in his career. Then the researcher has index h if h of his/her N papers have at least h citations each, and the other N − h papers have no more than h citations each.

For example −

If the citations array is −

const arr = [1, 6, 3, 0, 5];

This data represents that the researcher has 5 papers in total and each of them had received 1, 6, 3, 0, 5 citations respectively.

And since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, the h-index is 3.

Therefore, the output for this array should be −

const output = 3;

Following is the code −

const arr = [1, 6, 3, 0, 5]; const findHIndex = (arr = []) => { let possible = []; let { length: len } = arr; if (len === 0){ return 0; }; possible.length = len + 2; possible = possible.join('-').split('').map(() => 0); for (let i = 0; i < len; i ++) { let val = arr[i]; let ind = val > len ? len : val; possible[ind] += 1; } let result = 0; for (let k = len; k >= 0; k --) { result += possible[k]; if (result >= k) { return k; } } }; console.log(findHIndex(arr));

Following is the console output −

3

Advertisements