Skip to content

Instantly share code, notes, and snippets.

@tcdevs
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save tcdevs/c18d50e792c968b6d4f8 to your computer and use it in GitHub Desktop.

Select an option

Save tcdevs/c18d50e792c968b6d4f8 to your computer and use it in GitHub Desktop.
/*
IMPORTANT: requires Lo-Dash (http://lodash.com/) or Underscore.js (http://underscorejs.org/)
Usage: ng-repeat="item in items | fuzzyFilter:searchText"
*/
var app = angular.module('app', []);
app.filter('fuzzyFilter', function () {
return function (items, searchText) {
var searchWords;
if (searchText) {
searchWords = searchText.split(' ');
return _.filter(items, function (item) {
var itemText = _.values(item).join(' ').toLowerCase();
return _.every(searchWords, function (searchWord) {
return itemText.search(searchWord.toLowerCase()) !== -1;
});
});
} else {
return [];
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment