Created
August 22, 2014 12:51
-
-
Save tborychowski/b3a23cd924f215724854 to your computer and use it in GitHub Desktop.
JS :: fuzzy search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.fuzzy = function (s) { | |
var hay = this.toLowerCase(), i = 0, n = -1, l; | |
s = s.toLowerCase(); | |
for (; l = s[i++] ;) if (!~(n = hay.indexOf(l, n + 1))) return false; | |
return true; | |
}; | |
('a haystack with a needle').fuzzy('hay sucks'); // false | |
('a haystack with a needle').fuzzy('sack hand'); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment