Menu

Toshimaru's Blog

Factorial function in Ruby

def factorial(num)
  (1..num).inject(:*)
end

3!

factorial 3 #=> 6

10!

factorial 10 #=> 3628800

15!

factorial 15 #=> 1307674368000
Load more