2
0

intersection.js 552 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, push = Array.prototype.push
  6. , slice = Array.prototype.slice;
  7. module.exports = function (/*…list*/) {
  8. var lists;
  9. if (!arguments.length) slice.call(this);
  10. push.apply(lists = [this], arguments);
  11. lists.forEach(value);
  12. lists.sort(byLength);
  13. return lists.reduce(function (a, b) {
  14. return filter.call(a, function (x) { return contains.call(b, x); });
  15. });
  16. };