Created
September 26, 2015 02:14
-
-
Save brenapp/591e4da0d5b8a237e4dd to your computer and use it in GitHub Desktop.
A very basic Fuzzy Search in 66 bytes
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
/* Fuzzy Search in JavaScript in 66 bytes by SpeedyNinja | |
Creates a Regex of the Form x.*y.*z.* for query xyz and tests it against the list of terms | |
*/ | |
f=t=>s=>t.filter(x=>eval("/"+s.replace(/./,"$&.*")+"/gi").test(x)) | |
/* | |
Usage: | |
var search = f(["list", "of", "search", "terms"]) | |
search("er") -> ["search", "terms"] | |
^ ^ ^^ | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i made it not use eval and also saved 3 whole bytes
i think you misplaced the
g
regex flag, it wasn't present in the .replace call so something likewouldn't work, but it is there on the .test call where it's useless since it tells the regex engine to not return on the first match (pointless since .test only tests if a string matches the regex or not)