Advertisement
Guest User

Untitled

a guest
May 28th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. .filter('findMatches', [function() {
  2. return function findMatches(arr1, arr2) {
  3. // We cache because JS has some funny properties.
  4. var len1, len2, i, j, matches, match;
  5. // Because you're passing in strings
  6. arr1 = arr1.split(' ');
  7. arr2 = arr2.split(' ');
  8. // Since the container will always be filled with matches
  9. matches = [];
  10.  
  11. // Cache .length before loops.
  12. len1 = arr1.length;
  13. len2 = arr2.length;
  14. // Search
  15. for(i = 0; i < len1; i+=1) {
  16. match = arr1[i];
  17. for(j = 0; j < len2; j+=1) {
  18. // Add match to list, no soft checking.
  19. if(match === arr2[j]) { matches.push(match); }
  20. }
  21. }
  22. return matches;
  23. };
  24. }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement