isEqualWith.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var baseIsEqual = require('./_baseIsEqual');
  2. /**
  3. * This method is like `_.isEqual` except that it accepts `customizer` which
  4. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  5. * are handled by the method instead. The `customizer` is invoked with up to
  6. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  7. *
  8. * @static
  9. * @memberOf _
  10. * @since 4.0.0
  11. * @category Lang
  12. * @param {*} value The value to compare.
  13. * @param {*} other The other value to compare.
  14. * @param {Function} [customizer] The function to customize comparisons.
  15. * @returns {boolean} Returns `true` if the values are equivalent,
  16. * else `false`.
  17. * @example
  18. *
  19. * function isGreeting(value) {
  20. * return /^h(?:i|ello)$/.test(value);
  21. * }
  22. *
  23. * function customizer(objValue, othValue) {
  24. * if (isGreeting(objValue) && isGreeting(othValue)) {
  25. * return true;
  26. * }
  27. * }
  28. *
  29. * var array = ['hello', 'goodbye'];
  30. * var other = ['hi', 'goodbye'];
  31. *
  32. * _.isEqualWith(array, other, customizer);
  33. * // => true
  34. */
  35. function isEqualWith(value, other, customizer) {
  36. customizer = typeof customizer == 'function' ? customizer : undefined;
  37. var result = customizer ? customizer(value, other) : undefined;
  38. return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
  39. }
  40. module.exports = isEqualWith;