Programming-Idioms

History of Idiom 31 > diff from v59 to v60

Edit summary for version 60 :
[Go] +DemoURL

Version 59

2020-07-02, 15:04:43

Version 60

2020-07-02, 22:14:33

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)

Variables
f,i
Variables
f,i
Code
func f(i int) int {
  if i == 0 {
    return 1
  }
  return i * f(i-1)
}
Code
func f(i int) int {
  if i == 0 {
    return 1
  }
  return i * f(i-1)
}
Demo URL
https://play.golang.org/p/COD3jNcRSTW