Front End Developer – Interview Questions 12 years ago
fourth solution would be naming the function with the iterator (as in my example below) and calling indexOf(iterator) when the function is invoked
HN user
fourth solution would be naming the function with the iterator (as in my example below) and calling indexOf(iterator) when the function is invoked
Here's another one. Probably not very performant
function foo(count) {
var ret = []
for (var i=0; i < count; i++) {
ret [i] = function i() { return this.indexOf(i) }
}
return ret;
}