Javascript examples for Function:Function Recursion
Use global variables in function recursion
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*from ww w . j a va2 s. c o m*/ var match; var rec = function(a, res) { if (a < 0) { return res; } match = a % 2 == 0; if (match) { res.push(a); } return rec(a - 1, res); } var results = rec(10, []); console.log(results); } </script> </head> <body> </body> </html>