2 回答
TA贡献2012条经验 获得超12个赞
基本上,您必须编写一个函数来比较两个字符串(上面链接的问题中有一个示例函数)并循环遍历两个数组,一个一个比较字符串。
一些伪代码:
function checkSimilarity(s1, s2) {
// ... compare the strings s1 and s2
}
arrOne.forEach((s1) => {
arrTwo.forEach((s2) => {
if(checkSimilarity(s1, s2) > 0.5)
console.log("Match found between" + s1 + " and " + s2);
console.log(checkSimilarity(s1, s2));
}
});
});
TA贡献1859条经验 获得超6个赞
假设你有什么构成相似性的规则,你可以做
var ar = ['English Question Answering', 'Questions And Reviews Organic Milk', 'Facebook Page Discovery (En) - 1426357'];
var keyword = ['English Question Answering', 'Facebook Page Discovery (En)']
var ret = []
function similar(string1, string2) {
return (string1 === string2) ||
string1.includes(string2) ||
string2.includes(string1)
}
ar.forEach(val => {
if (keyword.some(word => similar(val, word))) {
ret.push(`*${val[0]}* - ***${val[1]}*** - Pay: *${val[3]}* - tasks: *${val[5]}*`);
}
})
添加回答
举报