mirror of https://github.com/lukechilds/docs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
479 B
24 lines
479 B
'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;
|
|
|