Skip to content

Instantly share code, notes, and snippets.

@lkrych
Created October 11, 2016 19:49
Show Gist options
  • Save lkrych/3e5554ec5691a8d2d1c6fa9d12e1a6b9 to your computer and use it in GitHub Desktop.
Save lkrych/3e5554ec5691a8d2d1c6fa9d12e1a6b9 to your computer and use it in GitHub Desktop.
Rewrite of the factorial method, Being used in RSpec blog post
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