You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.1 KiB

4 years ago
  1. var baseDifference = require('./_baseDifference'),
  2. baseFlatten = require('./_baseFlatten'),
  3. baseUniq = require('./_baseUniq');
  4. /**
  5. * The base implementation of methods like `_.xor`, without support for
  6. * iteratee shorthands, that accepts an array of arrays to inspect.
  7. *
  8. * @private
  9. * @param {Array} arrays The arrays to inspect.
  10. * @param {Function} [iteratee] The iteratee invoked per element.
  11. * @param {Function} [comparator] The comparator invoked per element.
  12. * @returns {Array} Returns the new array of values.
  13. */
  14. function baseXor(arrays, iteratee, comparator) {
  15. var length = arrays.length;
  16. if (length < 2) {
  17. return length ? baseUniq(arrays[0]) : [];
  18. }
  19. var index = -1,
  20. result = Array(length);
  21. while (++index < length) {
  22. var array = arrays[index],
  23. othIndex = -1;
  24. while (++othIndex < length) {
  25. if (othIndex != index) {
  26. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  27. }
  28. }
  29. }
  30. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  31. }
  32. module.exports = baseXor;