Tuesday, 2 July 2019

How to multiply the array elements in ruby?

a= [1,2,3,4,5,6,7,8]

Scenarios 1:
a.reduce(:*)

Scenarios 2:
b=1

a.each do |e|
  b=b*e
end


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...