

Show HN: Fuzzy search in 400B of JavaScript - bevacqua
https://github.com/bevacqua/fuzzysearch

======
acbart
So it's a "string contains string" function in Javascript? I mean, that's
great, and this seems like a simple and clean implementation, but is it really
worthy of a hacker news post? It seems like the answer to a stack overflow
question.

~~~
sync
Based on the first example, it seems a wee bit more complicated than that:

    
    
        fuzzysearch('twl', 'cartwheel') // <- true
    

The string 'cartwheel' does not contain the string 'twl' directly.

~~~
bshimmin
I think

    
    
        new RegExp("twl".split("").join("(.+)?")).test("cartwheel")
    

does approximately the same, no?

~~~
Guillaume86
Yes it's the same according to the source.

You can also use ".*" to replace "(.+)?" in your regex.

~~~
mistercow
It's only the same as long as your search string doesn't contain any special
characters as far as regex is concerned.

~~~
Guillaume86
Yes good catch. It's going to be a lot slower anyway. Still does a good job at
explaining the matching algorithm concisely.

