mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-08 03:50:13 +08:00
25 lines
479 B
JavaScript
25 lines
479 B
JavaScript
|
|
'use strict';
|
||
|
|
|
||
|
|
function fuzzysearch (needle, haystack) {
|
||
|
|
var tlen = haystack.length;
|
||
|
|
var qlen = needle.length;
|
||
|
|
if (qlen > tlen) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (qlen === tlen) {
|
||
|
|
return needle === haystack;
|
||
|
|
}
|
||
|
|
outer: for (var i = 0, j = 0; i < qlen; i++) {
|
||
|
|
var nch = needle.charCodeAt(i);
|
||
|
|
while (j < tlen) {
|
||
|
|
if (haystack.charCodeAt(j++) === nch) {
|
||
|
|
continue outer;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = fuzzysearch;
|