I have an array of CGFloats. I also have an arbitrary value a that can be any CGFloat. My question is, how do I efficiently find which two indices that a is between. As a side note, a will never be below or greater than the minimum or maximum of the Array, so there is no need to worry about that.
For a simplifed example, I may have:
let array: [CGFloat] = [4, 7, 10, 22, 23, 25, 67]
// a can be any random number, this initialization is for the example
let a = 14
// some algorithm that calculates indexes
// code returns index 2 and 3 (or it returns items 10, 22)
I have developed one method involving for loops, however, the larger the list is the more inefficient the code is. Is there any intelligent, and more efficient code out there?
Thanks for all the help :)