_baseXor.js 991 B

123456789101112131415161718192021222324252627282930
  1. var arrayPush = require('./_arrayPush'),
  2. baseDifference = require('./_baseDifference'),
  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 index = -1,
  16. length = arrays.length;
  17. while (++index < length) {
  18. var result = result
  19. ? arrayPush(
  20. baseDifference(result, arrays[index], iteratee, comparator),
  21. baseDifference(arrays[index], result, iteratee, comparator)
  22. )
  23. : arrays[index];
  24. }
  25. return (result && result.length) ? baseUniq(result, iteratee, comparator) : [];
  26. }
  27. module.exports = baseXor;