Ohm-Management - Projektarbeit B-ME
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.

index.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. var isArray = Array.isArray;
  3. var keyList = Object.keys;
  4. var hasProp = Object.prototype.hasOwnProperty;
  5. module.exports = function equal(a, b) {
  6. if (a === b) return true;
  7. if (a && b && typeof a == 'object' && typeof b == 'object') {
  8. var arrA = isArray(a)
  9. , arrB = isArray(b)
  10. , i
  11. , length
  12. , key;
  13. if (arrA && arrB) {
  14. length = a.length;
  15. if (length != b.length) return false;
  16. for (i = length; i-- !== 0;)
  17. if (!equal(a[i], b[i])) return false;
  18. return true;
  19. }
  20. if (arrA != arrB) return false;
  21. var dateA = a instanceof Date
  22. , dateB = b instanceof Date;
  23. if (dateA != dateB) return false;
  24. if (dateA && dateB) return a.getTime() == b.getTime();
  25. var regexpA = a instanceof RegExp
  26. , regexpB = b instanceof RegExp;
  27. if (regexpA != regexpB) return false;
  28. if (regexpA && regexpB) return a.toString() == b.toString();
  29. var keys = keyList(a);
  30. length = keys.length;
  31. if (length !== keyList(b).length)
  32. return false;
  33. for (i = length; i-- !== 0;)
  34. if (!hasProp.call(b, keys[i])) return false;
  35. for (i = length; i-- !== 0;) {
  36. key = keys[i];
  37. if (!equal(a[key], b[key])) return false;
  38. }
  39. return true;
  40. }
  41. return a!==a && b!==b;
  42. };