I'v heard this question, and I'm unsure as how to solve it.
The requirement is: implement the function from so it will preform like so on the following scenario:
var x = from(3);
console.log(x()); //outputs 3
console.log(x()); //outputs 4
//TODO: implement from()
I tried something like:
function from(val) {
var counter = val;
return function(){
return counter+=1;
}
}
But the first time I run it, it increments the value, So that's a no go.
counter+=1returncounter++, that waycounteris first returned, then incremented.