intersection.js 615 B

12345678910111213141516171819202122
  1. define(['./_getLength', './contains'], function (_getLength, contains) {
  2. // Produce an array that contains every item shared between all the
  3. // passed-in arrays.
  4. function intersection(array) {
  5. var result = [];
  6. var argsLength = arguments.length;
  7. for (var i = 0, length = _getLength(array); i < length; i++) {
  8. var item = array[i];
  9. if (contains(result, item)) continue;
  10. var j;
  11. for (j = 1; j < argsLength; j++) {
  12. if (!contains(arguments[j], item)) break;
  13. }
  14. if (j === argsLength) result.push(item);
  15. }
  16. return result;
  17. }
  18. return intersection;
  19. });