0

I'm getting myself confused with all these languages! :)

// given this function
var f = function(a,b) { return a == b; }

// and these values for a
var a = [1,2,3]

// how do I make this array (a is replaced by its value)?
var results = [
   function(b) { return 1 == b; },
   function(b) { return 2 == b; },
   function(b) { return 3 == b; }
]
2
  • how would you invoke this function? Commented Jan 27, 2012 at 17:51
  • @qwertymk I don't want to mess with its context if that's what you're getting at. Commented Jan 27, 2012 at 17:52

1 Answer 1

2
function build(a) {
    return function(b) { return a == b; }
}

var results = [];
var a = [1, 2, 3];

for (var i = 0; i < a.length; i++) {
    results.push(build(a[i]));
}    

Some output:

> results[0](1)
true
> results[0](2)
false
> results[1](1)
false
> results[1](2)
true
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.