I have an array of strings like so:
var inputArray= [
"Bob Johnson goes to the zoo",
"Timothy Smith likes to eat ice-cream",
"Jenny wants to play with her friends",
"There is no one in the room to play with Timothy",
"Jeremy Jones has been sleeping all day"
];
...and another array of names like so:
var names = [
"bob johnson",
"bob",
"timothy smith",
"timothy",
"jenny sanderson",
"jenny",
"jeremy jones",
"jeremy"
];
...and what I want to do is check each of the strings in the inputArray to see if they contain any of the names from the names array.
Whenever it finds a name match, it should do two things :
Push the name to an answerKey array like so:
var answerKey = [ "bob", "timothy", "jenny", "timothy", "jeremy" ];
and 2. Push the string with the name replaced by an '?' to another array (output) like so:
var output = [
"? goes to the zoo",
"? likes to eat ice-cream",
"? wants to play with her friends",
"There is no one in the room to play with ?",
"? has been sleeping all day"
];
I'm familiar with checking for substrings within strings but not when substrings are in one array and strings to be checked against are in another. Any help would be very appreciated :))