Let\'s say I have an array A = [1, 2, 3, 4, 5]
how can I multiply all elements with ruby and get the result? 1*2*3*4*5 = 120
and what if there is an element 0 ?
If you want to understand your code later on, use this: Assume A = 5, I used n instead of A
n = 5 n.times {|x| unless x == 0; n = n * x; ++x; end} p n
To carry it forward, you would:
A = [1,2,3,4,5] arb = A.first a = A.count a.times {|x| arb = arb * A[x]; ++x} p arb