Logo

Programming-Idioms

History of Idiom 31 > diff from v55 to v56

Edit summary for version 56 by programming-idioms.org:
[Elixir] Dead link: play.elixirbyexample.com has been down for a while

Version 55

2019-09-26, 22:27:27

Version 56

2019-10-14, 12:23:57

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