Skip to content

Instantly share code, notes, and snippets.

@andrewjkerr
Created November 15, 2015 21:48
Show Gist options
  • Save andrewjkerr/cfe3ca34b98c4810906c to your computer and use it in GitHub Desktop.
Save andrewjkerr/cfe3ca34b98c4810906c to your computer and use it in GitHub Desktop.
Ruby is great, isn't it?
# Accepts an integer n
# Returns the factorial of n
def fact(n)
return nil if n < 1
(1..(n.to_i)).reduce(:*)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment