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!
145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/openc3/core_ext/array.rb', line 145 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 |