(function () {
'use strict'
var objA = { name: "John", id: 3, age: 42 },
objB = { name: "Lucas", id: 3, age: 31}
var getDiff = function (objA, objB) {
var result = {};
if (!objA || !objB) {
console.log('You need to provide two objects');
return false;
};
for (var key in objA) {
console.log('Initializing key ' + key);
// iterate over objA's properties
if (objA.hasOwnProperty(key)) {
console.log('Object has own property: ', key)
var objATempValue = objA[key];
console.log('Key ' + key +' value is ', objATempValue)
if (objB.hasOwnProperty(key)) {
console.log('objB has key ' + key + ' with a value of ' + objB[key])
if (objB[key] !== objATempValue) {
console.log(objB[key] + ' is different from ' + objATempValue)
result[key] = objATempValue;
console.log('Our result is now...', result)
}
}else {
console.log(objB[key] + ' is equal from ' + objATempValue)
result[key] = objATempValue;
}
};
};
return result;
};
console.log(getDiff(objA, objB));
})();