# Differences

This shows you the differences between two versions of the page.

 algorithm:factorial_recursive [2012/10/04 21:59]127.0.0.1 external edit algorithm:factorial_recursive [2015/02/02 08:28] (current) Both sides previous revision Previous revision 2015/01/29 23:01 will 2015/01/29 23:01 will 2015/01/29 09:20 will 2015/01/29 09:18 will 2014/07/05 22:36 will 2014/05/04 16:25 external edit2013/05/04 14:45 will 2013/04/29 09:29 will 2013/04/29 09:20 will 2012/10/04 22:36 will [Visualisation] 2012/10/04 21:59 external edit2012/09/03 11:37 will created Next revision Previous revision 2015/01/29 23:01 will 2015/01/29 23:01 will 2015/01/29 09:20 will 2015/01/29 09:18 will 2014/07/05 22:36 will 2014/05/04 16:25 external edit2013/05/04 14:45 will 2013/04/29 09:29 will 2013/04/29 09:20 will 2012/10/04 22:36 will [Visualisation] 2012/10/04 21:59 external edit2012/09/03 11:37 will created Line 1: Line 1: - ====== Algorithm ====== + ======= λ Factorial - recursive ====== + + <​nowiki>​ + ======= Algorithm ​======= function fac(x) { function fac(x) { Line 9: Line 12: ​ - ====== Support ====== + ======= Support ​======= function run() { function run() { Line 16: Line 19: ​ - ====== Visualisation ====== + ======= Tests ======= + + function testTen() { + assert (fac(10) === 3628800, "​fac(10)"​);​ + } + + function testSeven() { + assert (fac(7) === 5040 , "​fac(7)"​);​ + }​ + + ======= Options ======= + + { + "​title":"​Factorial - recursive",​ + "​height":"​150px"​ + } + ​ + + ======= Visualisation ​======= <​html>​ <​html>​ Line 29: Line 50: var stack = x.stack; var stack = x.stack; for (var i=stack.length-1;​ i>=0; i--) { for (var i=stack.length-1;​ i>=0; i--) { - var x2 = stack[i].executionContext;​ + var a = stack[i].lookupInScope("​x"​);​ - var a = x2.lookupInScope("​x"​);​ + if (a) { if (a) { html = a+" * "​+html;​ html = a+" * "​+html;​ Line 46: Line 66: else { else { var a = x.lookupInScope("​x"​);​ var a = x.lookupInScope("​x"​);​ + if (!a) a = 50; html = html + "​fac("​+a+"​)";​ html = html + "​fac("​+a+"​)";​ } } Line 53: Line 74: ​ - ​ + ​ +