Logo

Programming-Idioms

History of Idiom 31 > diff from v5 to v6

Edit summary for version 6 by :

Version 5

2015-08-01, 17:28:07

Version 6

2015-08-19, 17:21:52

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
fn f(n: u32) -> u32 {
    if n < 2 {
        1
    } else {
        n * f(n - 1)
    }
}
Demo URL
http://is.gd/ZVwM65