Created
October 11, 2016 18:40
-
-
Save lkrych/ed30bd616a19cb5ccf0b23dbcb7a50b4 to your computer and use it in GitHub Desktop.
Factorial function in ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def factorial(n) | |
if n <= 0 | |
puts "sorry I only compute the factorial for positive numbers" | |
return | |
else | |
@product = 1 | |
(1..n).each do |number| | |
@product *= number | |
end | |
return @product | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment