I've implemented a factorial function in a more "Ruby" way. I would like to get feedback on the algorithm.
def factorial_of n (1..n).inject :* end factorial_of 5 => 120
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It only takes a minute to sign up.Sign up to join this community
The "of" in the name
factorial_of is redundant and unconventional.
factorial_of 0 returns
nil instead of the correct answer, which is
def factorial(n) (1..n).inject(1, :*) end