I\'ve a simple FOR statement like this:
var num = 10,
reverse = false;
for(i=0;i
when rever
Surely in a language like Javascript there must be a way to define a local function and use that in the loop?
function SubtractFrom(val, subtractor) {
return val - subtractor;
}
function PassThrough(val) {
return val;
}
var num = 10;
var processor = reverse ? SubtractFrom(num-1) : PassThrough;
for (i = 0; i < num; i++) {
console.log(processor(i));
}
Not knowing Javascript though, I don't know what actual form the function definitions would take.