I have the below Array with me.
scala> var a1 =Array(1.1,2.4,3.6)
a1: Array[Double] = Array(1.1, 2.4, 3.6)
I need to get the index from this array based on the input value as below.Basically, I need two index for a three element array.
For ex- all the input between 1.1 and 2.4 should be in first bucket. and all the input between 2.5 and 3.6 should be in second bucket.
> 1.1 -> 0
> 1.5 -> 0
> 2.4 -> 1
> 3.5 -> 1
> 3.6 -> 1
I was trying this using a1.indexWhere(x <= _). But this will result in the last item ie, 3.6 will fall in 3rd index.
Is there any simple way to achieve this ?