Method: Array#range_within

Defined in:
lib/openc3/core_ext/array.rb

#range_within(start_value, end_value) ⇒ Range

Returns the range of array elements which within both the start value and end value.

NOTE: This routine only works on sorted data!

Parameters:

  • start_value (Numeric)

    The start value to search for (must be less than end_value)

  • end_value (Numeric)

    The end value to search for

Returns:

  • (Range)

    The range of array elements which contain both the start_value and end_value



224
225
226
227
228
229
230
231
# File 'lib/openc3/core_ext/array.rb', line 224

def range_within(start_value, end_value)
  raise "end_value: #{end_value} must be greater than start_value: #{start_value}" if end_value < start_value

  range = Range.new(index_gt_eq(start_value), index_lt_eq(end_value))
  # Sometimes we get a backwards range so check for that and reverse it
  range = Range.new(range.last, range.first) if range.last < range.first
  range
end