Logo

Programming-Idioms

History of Idiom 31 > diff from v34 to v35

Edit summary for version 35 by programming-idioms.org:
[Elixir] Not an "inside code" comment

Version 34

2016-11-30, 22:18:56

Version 35

2016-11-30, 22:20:50

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
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)
Comments bubble
iex > Factorial.of(100)
Demo URL
http://play.elixirbyexample.com/s/90405f986e
Demo URL
http://play.elixirbyexample.com/s/90405f986e