Friday, 3 May 2019

Finding Dividable by 2 values in an ruby array

a = [1,2,3,4,444,6,5,6,7,8,44,55,333,555,66,88]
b = []
a.each do |h|
  b.push(h) if (h%2) == 0
end
p b

output:=> [2, 4, 444, 6, 6, 8, 44, 66, 88]

No comments:

Post a Comment

Interactor in Rails

What is interactor? Interactor provides a common interface for performing complex user interactions An interactor is a simple, sin...