Programming-Idioms

History of Idiom 31 > diff from v10 to v11

Edit summary for version 11 :

Version 10

2015-09-03, 17:18:13

Version 11

2015-09-04, 13:36:56

Idiom #31 Recursive factorial (simple)

Create recursive function f which returns the factorial of non-negative integer i, calculated from f(i-1)

Idiom #31 Recursive factorial (simple)

Create recursive function f which returns the factorial of non-negative integer i, calculated from f(i-1)

Code
defmodule Factorial do
  def of(0), do: 1
  def of(n) when n > 0 do
    n * of(n-1)
  end
end

# iex > Factorial.of(100)