How do you write a one line if that puts even values of my_array


#1



my code is a bit funny I need help. Here is what I wrote:


my_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

puts my_array[x] if x/2 <> 0


#2

Try using the array method, .each with a block:

my_array.each { |x| puts x if x % 2 == 0 }

will output only the even numbers. Change to != for odd numbers, only.