What I need to do is receive a list of strings and transform this in a list of functions that checks if a given key contains those respective strings. What I'm trying:
var words = ['f', 'b', 'b']; //I never know how this list is
for(i in words){
var str = words[i];
words[i] = function(key){
return key.indexOf(str) > -1;
}
}
After runnning this script, I was expecting to words
to become this:
[
function(key){
return key.indexOf('f') > -1;
},
function(key){
return key.indexOf('b') > -1;
},
function(key){
return key.indexOf('b') > -1;
}
]
But when I try words[0]('foo')
, It's returning me false
. What I'm doing wrong?