Skip to content

Instantly share code, notes, and snippets.

@kmandreza
Created January 12, 2013 04:20
Show Gist options
  • Save kmandreza/4516064 to your computer and use it in GitHub Desktop.
Save kmandreza/4516064 to your computer and use it in GitHub Desktop.
Write a method called product which takes as its input an array of integers and returns their product. For example product([1,2,3]) # returns 6 product([0,-1,-10]) # returns 0 product([1,-1,-10]) # returns -11 If you need to iterate over the array, please use Array#each. Don’t use, e.g., inject.
def product(x)
p = 1
x.each do |y|
p = p * y
end
p
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment