Guest User

Untitled

a guest
Sep 30th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. def product_except?(d)
  2. e = []
  3. startvalue = 0
  4. endvalue = d.length
  5. product = d.inject(1){|first,n| first * n}
  6. result = []
  7. while startvalue < endvalue
  8. result.push(product/ d[startvalue])
  9. startvalue = startvalue + 1
  10. end
  11. puts "#{result}"
  12. end
  13. product_except?([1,2,3,4,5,6,7,8,9])
Add Comment
Please, Sign In to add comment