= generateSearch $ \ (text query info index)
-- "return if matches"
if (is text query)
do $ return $ object (:match false) (:start 0)
-- "reurn false if text is using up"
if (and (is text.length 0) (> query.length 0))
do $ return $ object (:match false) (:start 0)
-- "return true if query is using up"
if (is query.length 0)
do $ return info
= nextIndex $ + index 1
-- "first letter matches, keep going without first letters"
if (is (. text 0) (. query 0))
do
if (< nextIndex info.start)
do $ = info.start nextIndex
return $ generateSearch (text.substr 1) (query.substr 1) info nextIndex
-- "first letter does not match, but keep going without first letter of text"
generateSearch (text.substr 1) query info nextIndex
= exports.fuzzyStart $ \ (list query)
= result $ list.map $ \ (text)
= info $ object (:start 10) (:match true) (:text text)
generateSearch text query info 0
-- "filter and sort"
= result $ result.filter $ \ (item) item.match
= result $ result.sort $ \ (a b)
cond
(< a.start b.start) -1
(> a.start b.start) 1
else 0
return $ result.map $ \ (item) item.text
Mine was in a functional one written in CirruScript(compiles with http://repo.cirru.org/script/):