I got stuck at a problem in JavaScript which uses the concept of function scope. Particularly, this is what I need to solve:
Define a function named callFunc that takes one argument, a function f. It should return an array containing the values f(0), f(0), f(1), f(1). You can only call f twice.
My code so far is:
var f = function(x) {
return x+2;
};
var callFunc = function (f) {
return [f(0), f(1)];
};
I don't know how I can return an array of four elements using only two calls and the JavaScript function scope principles.