This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ruby_tasks.rb | |
# 1. Дано цілочисельний масив. Вивести елементи з парними індексами, а потім з непарними. | |
data = [1, 2, 3, 4, 5, 6] | |
p (data.each_with_index.select { |_, i| i.even? } + data.each_with_index.select { |_, i| i.odd? }).map(&:first) | |
# 2. Дано цілочисельний масив. Вивести елементи з непарними індексами, а потім з парними. | |
data = [1, 2, 3, 4, 5, 6] | |
p (data.each_with_index.select { |_, i| i.odd? } + data.each_with_index.select { |_, i| i.even? }).map(&:first) |