Last active
August 29, 2015 14:19
-
-
Save brandonhesse/b165ce5d2eeebb436e5f to your computer and use it in GitHub Desktop.
Matches in both items
This file contains 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
.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; | |
}; | |
}]); |
This file contains 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
<p>{{ title|findMatches:title2 }}</p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment