3 回答

TA贡献1798条经验 获得超7个赞
我想你已经很接近了,我会像这样接近它
function searchString(input, match) {
let is_a_match = true;
const match_arr = match.split(' ');
const input_arr = input.split(' ');
input_arr.forEach(word => {
if (match_arr.indexOf(word) === -1) {
is_a_match = false;
}
});
return is_a_match;
}

TA贡献1828条经验 获得超3个赞
拆分F_Input“”,然后您可以使用 'Array.prototype.map()'F_Input使用您现在拥有的相同技术遍历搜索词数组。
请注意,我已将所有这些链接在一起,并最终调用该.every()方法。最后一个说每个map操作(搜索)都必须导致一个 true(或者map操作的结果必须导致一个只有 的数组true);
const F_Objectslist = "this is search term, and this is term search".split(' ');
const F_Input = "search term";
let result = search(F_Objectslist, F_Input);
console.log(result);
let notFoundResult = search(F_Objectslist, "search dog");
console.log(notFoundResult);
function search(text, terms) {
return terms.split(' ').map(term =>text.includes(term)).every(found=>found===true);
}
添加回答
举报