Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kmandreza/4516065 to your computer and use it in GitHub Desktop.
Save kmandreza/4516065 to your computer and use it in GitHub Desktop.
Write a method called product_odd which takes as its input an array of integers and returns the product of all the odd integers in the array. Remember that technically 0 is an even integer. For example: product_odd([1,2,3]) # returns 3, because 2 is even product_odd([0,-1,-10]) # returns -1, because 0 and -10 are even product_odd([1,2,3,4,5]) # …
def product_odd(x)
odd = x.select {|y| y%2 == 1}
p = 1
odd.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