No need for the regex, just loop through the words using every()
, and check each keyword using includes()
(See below);
console.log(Check("How to edit an image", ["image","edit","not"])); // false
console.log(Check("How to edit an image", ["image","edit"])); // true
function Check(title, keywords) {
return keywords.every(word => title.indexOf(word) > -1);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…