I was looking for my answer and found this: multiple conditions for JavaScript .includes() method
but, this solution does either one or all of the words from the list:
//checks for one
const multiSearchOr = (text, searchWords) => (
searchWords.some((el) => {
return text.match(new RegExp(el,"i"))
})
)
//checks for all
const multiSearchAnd = (text, searchWords) => (
searchWords.every((el) => {
return text.match(new RegExp(el,"i"))
})
)
These work, but i need to be able to match on two or more words in my passed in list. Like the following:
let name = "jaso bour 2";
let spl = name.split(' ');
let passed = multiSearchAnd("my name is jason bourne the fourth on the fifth", spl);
console.log(passed);
The variable passed in the above scenario is false but i want it to be true since the strings "jaso" and "bour" are in the searched string.
How do i alter the multiSearchAnd function so it will return true if two or more words are found from the passed in list and not just all of them? Thanks