Skip to content

Instantly share code, notes, and snippets.

@httnn
Created July 22, 2015 09:12
Show Gist options
  • Save httnn/0f78d5c06dc3ba667a74 to your computer and use it in GitHub Desktop.
Save httnn/0f78d5c06dc3ba667a74 to your computer and use it in GitHub Desktop.
fuzzy searching with JavaScript
var matches = function(string, q) {
q = q.toLowerCase().replace(/[^\w]/g, '');
var inner = function(string, q) {
if (q.length) {
var i = string.indexOf(q[0]);
return i > -1 ? inner(string.substr(i), q.substr(1)) : false;
}
return true;
};
return inner(string.toLowerCase(), q);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment