Here is the code snippet I'm working with:
// Finding multiple keywords within a text
// Scenario 1
var inputText = "Hello, My name is @Steve, I love @Bill, happy new year!";
var terms = ["steve"];
var result = inputText.toLowerCase().search([terms]);
console.log(result);
// Expected output: 19
// Scenario 2
var inputText = "Hello, My name is @Steve, I love @Bill, happy new year!";
var terms = ["bill"];
var result = inputText.toLowerCase().search([terms]);
console.log(result);
// Expected output: 34
// Scenario 3
var inputText = "Hello, My name is @Steve, I love @Bill, happy new year!";
var terms = ["steve, bill"];
var result = inputText.toLowerCase().search([terms]);
console.log(result);
// Expected output: -1
// Scenario 4
var inputText = "Hello, My name is @Steve, I love @Bill, happy new year!";
var terms = ["steve", "bill"];
var result = inputText.toLowerCase().search([terms]);
console.log(result);
// Expected output: -1
Is there something missing to make Scenario 3 and Scenario 4 return positive results?
I am looking for a way to ensure that if the text matches at least one of the keywords, it should return a positive result.
Currently, this approach is not yielding the desired outcome. Any assistance would be greatly appreciated. Thank you.
Thank you.