Skip to content

Instantly share code, notes, and snippets.

# 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)