4 ms·
is it me or this is confusing? "Define a function named generate that takes one argument, a function f. It should return an array that consists of the function
by jordinl 15y ago
is it me or this is confusing?
"Define a function named generate that takes one argument, a function f. It should return an array that consists of the function f and another function that doubles its input."
- jonsen 15y agoDefine a function var ... = function( ... ){ ... }; named generate var generate = function( ... ){ ... }; that takes one argument, a function f var generate = function( f ){ ... }; It should return an array var generate = function( f ){ return [ ... ]; }; that consists of the function f var generate = function( f ){ return [ f, ... ]; }; and another function var generate = function( f ){ return [ f, function( ... ){ ... } ]; }; that doubles its input var generate = function( f ){ return [ f, function( x ){ return 2*x; } ]; };
- pankajdoharey 15y agoYour Answer is superb but can you tell me what is wrong with this var generate = function (f) { var double = function (x){return x * 2;}; var list = [f,double]; return list; }; On the other hand this one passes the JSLInt test given here at : http://nathansjslessons.appspot.com/lesson?id=1050 http://nathansjslessons.appspot.com/lesson?id=1050 var generate = function (f) { function double(x){return x * 2;} var list = [f,double]; return list; };
- jonsen 15y agoI'm sorry I can't. I'm not into the details of Javascript (yet) and know nothing about JSLint.