Created
February 4, 2019 14:58
-
-
Save kevbook/4c100c1cfc3a06dc12d344fbd5e0713c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = { | |
a: 1, | |
b: 'hello', | |
c: undefined, | |
d: 2, | |
e: '2', | |
g: null, | |
h: '5', | |
i: [1, 2, 3, 4, { a: { a: 'a' } }], | |
f: { | |
b: 1, | |
a: null, | |
c: { | |
b: 2, | |
a: 1, | |
c: { | |
a: 1 | |
} | |
} | |
} | |
}; | |
// not equal to a | |
var b = { | |
a: 1, | |
b: 'hello', | |
c: null, | |
d: 2, | |
e: '2', | |
g: null, | |
h: '5', | |
i: [1, 2, 3, 4, { a: { a: 'a' } }], | |
f: { | |
b: 1, | |
a: null, | |
c: { | |
b: 2, | |
a: 1, | |
c: { | |
a: 1 | |
} | |
} | |
} | |
}; | |
// not equal to a | |
var c = { | |
a: 1, | |
b: 'hello', | |
c: undefined, | |
d: 2, | |
e: '2', | |
g: null, | |
h: '5', | |
i: [1, 2, 3, 4, { a: { a: 'b' } }], | |
f: { | |
b: 1, | |
a: null, | |
c: { | |
b: 2, | |
a: 1, | |
c: { | |
a: 1 | |
} | |
} | |
} | |
}; | |
// equal to a | |
var d = { | |
c: undefined, | |
a: 1, | |
b: 'hello', | |
d: 2, | |
e: '2', | |
g: null, | |
h: '5', | |
i: [1, 2, 3, 4, { a: { a: 'a' } }], | |
f: { | |
b: 1, | |
a: null, | |
c: { | |
b: 2, | |
a: 1, | |
c: { | |
a: 1 | |
} | |
} | |
} | |
}; | |
// not equal to a | |
var e = { | |
a: 1, | |
b: 'hello', | |
d: 2, | |
c: undefined, | |
e: '2', | |
g: null, | |
h: '5', | |
i: [1, 2, 3, 4, { a: { a: 'a' } }], | |
f: { | |
b: 1, | |
a: null, | |
c: { | |
b: null, | |
a: 1, | |
c: { | |
a: 1 | |
} | |
} | |
} | |
}; | |
/** | |
* @param o1 {Object} | |
* @param o2 {Object} | |
* @return {Boolean} | |
*/ | |
function isEqual(o1, o2) {} | |
console.log('Is a and a equal?', isEqual(a, a)); // true | |
console.log('Is a and b equal?', isEqual(a, b)); // false | |
console.log('Is a and c equal?', isEqual(a, c)); // false | |
console.log('Is a and d equal?', isEqual(a, d)); // true | |
console.log('Is a and d equal?', isEqual(a, e)); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Function isEqual accepts 2 js objects and returns a boolean if the objects are the same.