Skip to content

Instantly share code, notes, and snippets.

@xgrommx
Forked from brenapp/fuzzysearch.js
Created September 27, 2015 20:21
Show Gist options
  • Save xgrommx/39f0f1cc80b85edcce74 to your computer and use it in GitHub Desktop.
Save xgrommx/39f0f1cc80b85edcce74 to your computer and use it in GitHub Desktop.
A very basic Fuzzy Search in 66 bytes
/* 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