当邮件包含一个问候语和一个名字时,我希望控制台打印为true。
实施例。 1 message = ['hey john'] // true
实施例。 2 message = ['yo johnny'] // false
实施例。 3 message = ['hello johnny'] // true
实施例。 4 message = ['hey evan'] // false
// fetch query
String fetchUser = "SELECT * FROM user WHERE email = ?";
pre = conn.prepareStatement(fetchUser);
pre.setString(1, emailParam);
答案 0 :(得分:0)
您可以这样检查:
const greetings = ['hi', 'hello', 'hey']
const names = ['john', 'johnny']
const isIncludes = (msg, arr) => {
for (let i in arr) {
if (msg.includes(arr[i])) {
return true
}
}
return false;
}
message = ['hey john'] //true
console.log(isIncludes(message[0], greetings) && isIncludes(message[0], names))
message = ['yo johnny'] //false
console.log(isIncludes(message[0], greetings) && isIncludes(message[0], names))
message = ['hello johnny'] //true
console.log(isIncludes(message[0], greetings) && isIncludes(message[0], names))
message = ['hey evan'] //false
console.log(isIncludes(message[0], greetings) && isIncludes(message[0], names))
message = [''] //false
console.log(isIncludes(message[0], greetings) && isIncludes(message[0], names))