I'm not sure if I describe the question right, So I'll give a simple example.
Let's say I have an array:
var array = [0, 1.1, 2, 2.4, 4, 4.6, 5];
Given a number, 2.1
I want to find what index interval does it fall in.
For this question, the answer will be 2,3.
Currently I have two ideas for this, first one is simple but definitely very slow, which is loop through the whole array and find where array[i-1] is less than 2.1 and array[i] is greater than 2.1.
Another way is, add 2.1 to the array, sort the array in ascending order, the answer will be the index of 2.1, and this index - 1.
Any other better suggestions?