Created
October 11, 2016 19:49
-
-
Save lkrych/3e5554ec5691a8d2d1c6fa9d12e1a6b9 to your computer and use it in GitHub Desktop.
Rewrite of the factorial method, Being used in RSpec blog post
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_while(n) | |
if n <= 0 | |
puts "sorry I only compute the factorial for positive numbers" | |
return | |
else | |
idx = n | |
product = 1 | |
while idx > 1 | |
product *= idx | |
idx -= 1 | |
end | |
return product | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment