Programming-Idioms

History of Idiom 31 > diff from v33 to v34

Edit summary for version 34 :
[Elixir] Moved comments. +DemoURL

Version 33

2016-04-07, 06:53:49

Version 34

2016-11-30, 22:18: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)
Code
defmodule Factorial do
  def of(0), do: 1
  def of(n) when n > 0 do
    n * of(n-1)
  end
end
Comments bubble
# iex > Factorial.of(100)
Demo URL
http://play.elixirbyexample.com/s/90405f986e