How can I use underscore to filter an array based on another array1 and get the resulting answer? To clarify, I want to keep elements in the array where any of the key1 values match any sentence in array1. For instance:
var array = [{key: "ignore", key1: ["Alice doesn't", "Bob lives", "Charles is here"]},
{key: "not important", key1: ["David might", "Eve lives", "Frank can't"]}]
var array1 = ["Someone named Bob lives here", "Someone named Eve lives here", "Someone named Grace lives here"];
var answer = [{key: "ignore", key1: ["Alice doesn't", "Bob lives", "Charles is here"]}];
I have tried the following approaches so far:
var answerTest = _.filter(array, function(n){if(_.intersection(n.key1, array1))}); //this doesn't work as expected
var answerTest2 = _.filter(array, function(n){return RegExp(n.key1).test(????)})
I believe that answerTest2 provides a better solution, but I am unsure how to proceed from there.