I have a sorted array of Javascript date objects, the array always has a length of 14 entries. In pseudo:
dates
["label1"] = date object 1,
["label2"] = date object 2,
...
["label14"] = date object 14
Although they are in sorted order by date, the dates are not distributed evenly. For example, between entry 1 and 2 may be 1 hour, whilst between entry 5 and 6 are a few minutes, or a few hours.
My challenge is to find an algorithm that for any given input date, will find the following from this array:
- The position in the array of the previous date
- The position in the array of the next date
- Our input date will fall in between the above dates, I'd like to know the percentage in time between the 2 points. For example, exactly in between the dates would return 50%.
I don't like asking "please code this for me" questions but I'm really no good in writing efficient alghorithms and have been unsuccesful in finding an existing alghorithm.