test_1 | (function() {
for (const currentQueryWord of queryWords) {
let found = false;
for (const word of words) {
if (contains(word, currentQueryWord)) {
found = true;
break;
}
}
if (!found) return false;
}
})();
function contains(word, query) {
for (let start = 0; start + query.length <= word.length; ++start) {
const substring = word.substring(start, start + query.length);
if(substring === query) return true;
}
return false;
}
| ready |
test_2 | function contains(word, query) {
return word.includes(query);
}
(function(){
for (const currentQueryWord of queryWords) {
let found = false;
for (const word of words) {
if (contains(word, currentQueryWord)) {
found = true;
break;
}
}
if (!found) return false;
}
})();
| ready |
kmp | (function() {
for (const currentQueryWord of queryWords) {
let found = false;
for (const word of words) {
if (contains(word, currentQueryWord)) {
found = true;
break;
}
}
if (!found) return false;
}
})();
function contains(word, query) {
const prefixTable = createPrefixTable(pattern);
let j = 0;
let i = 0;
while (i < text.length) {
if(!text[i].localeCompare(pattern[j], 'en', {
sensitivity: 'base',
usage: "search",
ignorePunctuation: true
})) {
i++;
j++;
if (j === pattern.length) {
return i - j;
}
}
else if (j > 0) {
j = prefixTable[j - 1];
}
else {
i++;
}
}
return -1;
}
function createPrefixTable(pattern) {
const prefixTable = new Array(pattern.length).fill(0);
let j = 0;
for (let i = 1; i < pattern.length; i++) {
while (j > 0 && pattern[i] !== pattern[j]) {
j = prefixTable[j - 1];
}
if (pattern[i] === pattern[j]) {
j++;
}
prefixTable[i] = j;
}
return prefixTable;
}
| ready |