function top_avg(students){
var len = students.length;
var top01 = 40;
if(len > 10000){
top01 = 80;
}
var sum = 0.0;
for (var i = 0; i < top01; i++) {
sum += students[i].marks;
}
return sum/top01;
}
The above code means, everyone rank will jump suddenly when the $10000^{th}$ user comes, while that’s fine, it can be improved.
By calculating the $top01$ value dynamically based on the length of `students.length`, just multiply by $0.0001$
Unless its already done. I just checked the $github$.