exclusion.js 805 B

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. var value = require("../../object/valid-value")
  3. , aFrom = require("../from")
  4. , toArray = require("../to-array")
  5. , contains = require("./contains")
  6. , byLength = require("./_compare-by-length")
  7. , filter = Array.prototype.filter
  8. , push = Array.prototype.push;
  9. module.exports = function (/* …lists*/) {
  10. var lists, seen, result;
  11. if (!arguments.length) return aFrom(this);
  12. push.apply(lists = [this], arguments);
  13. lists.forEach(value);
  14. seen = [];
  15. result = [];
  16. lists.sort(byLength).forEach(function (list) {
  17. result = result
  18. .filter(function (item) {
  19. return !contains.call(list, item);
  20. })
  21. .concat(
  22. filter.call(list, function (item) {
  23. return !contains.call(seen, item);
  24. })
  25. );
  26. push.apply(seen, toArray(list));
  27. });
  28. return result;
  29. };