Вот мой код:Сопоставление нескольких ключевых слов в тексте (Javascript)
// Matching multiple keywords in a text
// Case 1
var text = "Hello, My name is @Steve, I love @Bill, happy new year!";
var keywords = ["steve"];
var matching = text.toLowerCase().search([keywords]);
console.log(matching);
// return 19
// Case 2
var text = "Hello, My name is @Steve, I love @Bill, happy new year!";
var keywords = ["bill"];
var matching = text.toLowerCase().search([keywords]);
console.log(matching);
// return 34
// Case 3
var text = "Hello, My name is @Steve, I love @Bill, happy new year!";
var keywords = ["steve, bill"];
var matching = text.toLowerCase().search([keywords]);
console.log(matching);
// return -1
// Case 4
var text = "Hello, My name is @Steve, I love @Bill, happy new year!";
var keywords = ["steve", "bill"];
var matching = text.toLowerCase().search([keywords]);
console.log(matching);
// return -1
Если что-то я пропустил, чтобы сделать Case 3 и Case 4 возвращение положительным?
Я просто хочу, если текст либо соответствие с одним из ключевых слов, он будет вернуть положительный.
Но не работает в данный момент. Помогает. Благодарю.
Спасибо.
Где функция 'search()', которая принимает массив строк как фактически определенный параметр? –
Вы можете попробовать на http://repl.it Поиск() определяется по умолчанию в js, справа? –