Guest User

Untitled

a guest
Jan 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. function isEqual(obj1, obj2) {
  2. for (var i in obj1) {
  3. if (obj1.hasOwnProperty(i)) {
  4. if (obj2[i] !== obj1[i]) {
  5. return false;
  6. }
  7. }
  8. }
  9. // No need for any else clause there, since any code after a return statement won't be executed.
  10. return true;
  11. }
  12.  
  13. // Console
  14.  
  15. >>> isEqual({a: 1}, {a : 1})
  16. true
  17. >>> isEqual({}, {})
  18. true
  19. >>> isEqual({a: 1, b: 2}, {b: 2, a: 1})
  20. true
Add Comment
Please, Sign In to add comment