From b9453a87e8b4ca3c9cb2f74f3b1575f7d6c597c4 Mon Sep 17 00:00:00 2001 From: Artem Darius Weber Date: Fri, 29 Nov 2024 15:46:55 +0300 Subject: [PATCH] feat: add minimal_even_element function to retrieve the smallest even element from an array --- lab3_task1_funcation_block_arg/main.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lab3_task1_funcation_block_arg/main.rb b/lab3_task1_funcation_block_arg/main.rb index f2bbf90..6f150bb 100644 --- a/lab3_task1_funcation_block_arg/main.rb +++ b/lab3_task1_funcation_block_arg/main.rb @@ -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(", ") \ No newline at end of file +puts elements_between_first_and_last_max(array).join(", ") + +array = [5, 2, 8, 3, 7] +puts "Minimal even element:" +puts minimal_even_element(array)