/**
* 传入两个字符串,返回相似度 * luzhipeng * @DateTime 2017-01-03T10:33:28+0800 * {String} * {String} * {Number} */ function checkSimilarity(s1, s2) { // 如果完整包含,则认为相似度为 0.95 if (s1.indexOf(s2) >= 0 || s2.indexOf(s1) >= 0) return 0.95; const regex = new RegExp(`(?=.*?)[^${s1}](?=.*?)|(?=.*?)[^${s2}](?=.*?)`, 'g'); let diffChars = 0; while (regex.exec(s1 + s2)) { diffChars++; } return (1 - diffChars / (s1.length + s2.length)) }