|
|
|
@ -24,6 +24,17 @@ def elements_between_first_and_second_max(array)
|
|
|
|
|
first_max_index, second_max_index = [first_max_index, second_max_index].sort
|
|
|
|
|
array[(first_max_index + 1)...second_max_index]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def elements_between_first_and_last_max(array)
|
|
|
|
|
max_value = array.max
|
|
|
|
|
first_max_index = array.index(max_value)
|
|
|
|
|
last_max_index = array.rindex(max_value)
|
|
|
|
|
return [] if first_max_index == last_max_index
|
|
|
|
|
|
|
|
|
|
first_max_index, last_max_index = [first_max_index, last_max_index].sort
|
|
|
|
|
array[(first_max_index + 1)...last_max_index]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Ex
|
|
|
|
@ -34,3 +45,7 @@ puts indices_sorted_by_descending_values(array).join(", ")
|
|
|
|
|
array = [5, 1, 8, 3, 8, 7]
|
|
|
|
|
puts "Elements between first and second maximum:"
|
|
|
|
|
puts elements_between_first_and_second_max(array).join(", ")
|
|
|
|
|
|
|
|
|
|
array = [5, 1, 8, 3, 7, 8]
|
|
|
|
|
puts "Elements between first and last maximum:"
|
|
|
|
|
puts elements_between_first_and_last_max(array).join(", ")
|