brewersfan1976

array_elements_product.rb

Feb 27th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.46 KB | None | 0 0
  1. def arrayElementsProduct(inputArray)
  2.     x = 0
  3.     array_length = inputArray.length
  4.    
  5.     if array_length == 1 then
  6.         return inputArray[x]
  7.     end
  8.        
  9.     if array_length == 2 then
  10.         return inputArray[x] * inputArray[x + 1]
  11.     end
  12.    
  13.     sum = inputArray[x] * inputArray[x + 1]
  14.        
  15.     x = 2
  16.        
  17.     while (x < array_length)
  18.           sum = sum * inputArray[x]
  19.           x = x + 1
  20.     end
  21.    
  22.     return sum
  23. end
Advertisement
Add Comment
Please, Sign In to add comment