index.js 805 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*!
  2. * arr-diff <https://github.com/jonschlinkert/arr-diff>
  3. *
  4. * Copyright (c) 2014-2017, Jon Schlinkert.
  5. * Released under the MIT License.
  6. */
  7. 'use strict';
  8. module.exports = function diff(arr/*, arrays*/) {
  9. var len = arguments.length;
  10. var idx = 0;
  11. while (++idx < len) {
  12. arr = diffArray(arr, arguments[idx]);
  13. }
  14. return arr;
  15. };
  16. function diffArray(one, two) {
  17. if (!Array.isArray(two)) {
  18. return one.slice();
  19. }
  20. var tlen = two.length
  21. var olen = one.length;
  22. var idx = -1;
  23. var arr = [];
  24. while (++idx < olen) {
  25. var ele = one[idx];
  26. var hasEle = false;
  27. for (var i = 0; i < tlen; i++) {
  28. var val = two[i];
  29. if (ele === val) {
  30. hasEle = true;
  31. break;
  32. }
  33. }
  34. if (hasEle === false) {
  35. arr.push(ele);
  36. }
  37. }
  38. return arr;
  39. }