feat: add minimal_even_element function to retrieve the smallest even element from an array

lab3
Artem-Darius Weber 1 month ago
parent 988d9c83dd
commit b9453a87e8

@ -37,6 +37,12 @@ def elements_between_first_and_last_max(array)
end
def minimal_even_element(array)
even_elements = array.select(&:even?)
even_elements.min
end
# Ex
array = [5, 3, 8, 1, 7]
puts "Indices in order of decreasing elements:"
@ -48,4 +54,8 @@ 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(", ")
puts elements_between_first_and_last_max(array).join(", ")
array = [5, 2, 8, 3, 7]
puts "Minimal even element:"
puts minimal_even_element(array)

Loading…
Cancel
Save