Logo

Programming-Idioms

History of Idiom 31 > diff from v3 to v4

Edit summary for version 4 by :

Version 3

2015-08-01, 17:26:03

Version 4

2015-08-01, 17:26:32

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
sub f {
   my $n = shift;
   return $n<0 ? 1 : $n * f($n-1);
}
Code
sub f {
   my $n = shift;
   return $n<2 ? 1 : $n * f($n-1);
}