Method: Array#index_lt_eq
- Defined in:
- lib/openc3/core_ext/array.rb
#index_lt_eq(value) ⇒ Fixnum
Returns the index of the first element which is less than or equal to the passed in value.
NOTE: This routine only works on sorted data!
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/openc3/core_ext/array.rb', line 161 def index_lt_eq(value) index = nearest_index(value) # Keep backing up if self[index - 1] == value to move past duplicates while index > 0 and self[index - 1] == value index -= 1 end return index if self[index] <= value index -= 1 if index > 0 return index end |