λ Factorial - iterative

======= Algorithm ======= <syntax js> function fac(x) { var n = 1; for (var i=2; i<=x; i++) { n *= i; } return n; } </syntax> ======= Support ======= <syntax js> function run() { return fac(50); } </syntax> ======= Tests ======= <syntax js> function testTen() { assert (fac(10) === 3628800, "fac(10)"); } function testSeven() { assert (fac(7) === 5040 , "fac(7)"); }</syntax> ======= Options ======= <syntax js> { "title":"Factorial - iterative", "height":"150px" } </syntax> ======= Visualisation ======= <syntax html> <html> <head> <script type="text/javascript"> function update(n, x) { var element = document.getElementById("container"); var r = x.returnedValue; var html = ""; if (r) { html = "" + r; } else { var n = x.lookupInScope("n"); var i = x.lookupInScope("i"); html = i? "i = "+i+"<br>" : "<br>"; if (n) { html += "n = " + n; } } element.innerHTML = html; } </script> </head> <body id="container"> </body> </html> </syntax>