intersection.js 588 B

12345678910111213141516171819
  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) { return contains.call(list2, item); });
  16. });
  17. };