SHARE
TWEET

Untitled

a guest Aug 17th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const equals = (a, b) => {
  2.       if (a === b) return true;
  3.       if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
  4.       if (!a || !b || (typeof a !== 'object' && typeof b !== 'object')) return a === b;
  5.       if (a === null || a === undefined || b === null || b === undefined) return false;
  6.       if (a.prototype !== b.prototype) return false;
  7.       let keys = Object.keys(a);
  8.       if (keys.length !== Object.keys(b).length) return false;
  9.       return keys.every(k => equals(a[k], b[k]));
  10.   };
  11.  
  12.   console.log(equals({ a: 1, b: 2}, { b: 2, a: 1}))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top