intersection.js 591 B

123456789101112131415161718192021
  1. "use strict";
  2. var value = require("../../object/valid-value")
  3. , contains = require("./contains")
  4. , byLength = require("./_compare-by-length")
  5. , filter = Array.prototype.filter
  6. , push = Array.prototype.push
  7. , slice = Array.prototype.slice;
  8. module.exports = function (/* …list*/) {
  9. var lists;
  10. if (!arguments.length) slice.call(this);
  11. push.apply(lists = [this], arguments);
  12. lists.forEach(value);
  13. lists.sort(byLength);
  14. return lists.reduce(function (list1, list2) {
  15. return filter.call(list1, function (item) {
  16. return contains.call(list2, item);
  17. });
  18. });
  19. };