I am very stupid, ask for help to solve an algorithm problem, about the algorithm to judge whether the current value is within the range value.

  node.js, question


I need to get the scrolltop value of the page every time I scroll, and then judge the interval index of this value in the above array, how to calculate? seek help


function getRangeIndex() {
 var i=0;
 for (;  i<ranges.length;  Icaga)
 if (scrollTop<ranges[i]) break;
 return i-1;