Skip to content

Instantly share code, notes, and snippets.

@kevbook
Created February 4, 2019 14:58
Show Gist options
  • Save kevbook/4c100c1cfc3a06dc12d344fbd5e0713c to your computer and use it in GitHub Desktop.
Save kevbook/4c100c1cfc3a06dc12d344fbd5e0713c to your computer and use it in GitHub Desktop.
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
@kevbook
Copy link
Author

kevbook commented Feb 4, 2019

Function isEqual accepts 2 js objects and returns a boolean if the objects are the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment