function match(string, pattern) {
var letterFound;
if (string.indexOf(pattern) != -1) {
letterFound = true;
} else letterFound = false;
return letterFound
}
console.log(match("abcdef", "!A2B$")); //should return true
console.log(match("abcdef", "FAce")); //should return true
console.log(match("abcdef", "FG")); //should return false
我遇到的问题是该函数应该查看字符串并查看模式,如果字符串中包含所有字母,则返回true。它应该忽略模式中包含的符号。简单的javascript将非常感激。
答案 0 :(得分:0)
这很好用。
function match(string, pattern) {
string = string.toLowerCase(), pattern = patten.toLowerCase();
for (var i = 0; i < pattern.length; i++) {
if (string.indexOf(pattern[i]) != -1) {
return true;
break; // match found
} else {
continue; // no match, move to next character in the pattern
}
}
return false;
}