Created
March 15, 2019 06:00
-
-
Save fallroot/62492d23058533e1a2e1509b19497563 to your computer and use it in GitHub Desktop.
Tiny Fuzzzy Search
This file contains hidden or 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
function search (text, keyword) { | |
let start = 0 | |
text = text.toLowerCase() | |
keyword = keyword.toLowerCase() | |
for (let i = 0; i < keyword.length; ++i) { | |
const char = keyword[i] | |
const index = text.indexOf(char, start) | |
if (index < 0) { | |
return false | |
} | |
start = index + 1 | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment