Logo

Programming-Idioms

History of Idiom 31 > diff from v4 to v5

Edit summary for version 5 by :

Version 4

2015-08-01, 17:26:32

Version 5

2015-08-01, 17:28:07

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
function f(n) {
   if (n<2) return 1;
   return n * f(n-1);
}
Code
function f(n) {
   return n<2 ? 1 : n * f(n-1);
}