Using jQuery I'm trying to find an efficient way to iterate through an array excludeMe
and check if elements from another array needsExclusions
are contained in the excludeMe
array. Not sure if this is the most efficient, but it works. Fiddle here: http://jsfiddle.net/yef9q/3/
//Iterate through needsExclusions for an excludeMe string
//someFlag raised on matching strings
var excludeMe = ["in west", "philadelphia", "born and", "raised"];
var needsExclusions = ["philadelphia", "raised"];
var someFlag = true;
$.each(excludeMe, function(i,val) {
//alert("value: " + val);
if ($.inArray(val, needsExclusions) != -1) {
alert("matching value: " + val);
someFlag = false;
}
});
intersection
algorithm – megawac Jul 22 '14 at 20:23