Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .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;
- };
- }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement