Skip to content

Instantly share code, notes, and snippets.

@brandonhesse
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonhesse/b165ce5d2eeebb436e5f to your computer and use it in GitHub Desktop.
Save brandonhesse/b165ce5d2eeebb436e5f to your computer and use it in GitHub Desktop.
Matches in both items
.filter('findMatches', [function() {
return function findMatches(arr1, arr2) {
// We cache because JS has some funny properties.
var len1, len2, i, j, matches, match;
// Because you're passing in strings
arr1 = arr1.split(' ');
arr2 = arr2.split(' ');
// Since the container will always be filled with matches
matches = [];
// Cache .length before loops.
len1 = arr1.length;
len2 = arr2.length;
// Search
for(i = 0; i < len1; i+=1) {
match = arr1[i];
for(j = 0; j < len2; j+=1) {
// Add match to list, no soft checking.
if(match === arr2[j]) { matches.push(match); }
}
}
return matches;
};
}]);
<p>{{ title|findMatches:title2 }}</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment