Skip to content

Commit

Permalink
[patch] fix nested empty objects being empty
Browse files Browse the repository at this point in the history
  • Loading branch information
omgaz committed Jul 23, 2019
1 parent 69e8864 commit 9b9a754
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function diffler(obj1, obj2) {

// If property exists in obj1 and not in obj2 then it has been removed
if (!(key in obj2)) {
if(!diff) { diff = {}; }
diff[key] = {
from: obj1Val,
to: null // using null to specify that the value is empty in obj2
Expand All @@ -26,15 +25,15 @@ function diffler(obj1, obj2) {
// If property is an object then we need to recursively go down the rabbit hole
else if(typeof obj1Val === 'object') {
var tempDiff = diffler(obj1Val, obj2Val);
if(tempDiff) {
if(!diff) { diff = {}; }
diff[key] = tempDiff;
if(Object.keys(tempDiff).length > 0) {
if(tempDiff) {
diff[key] = tempDiff;
}
}
}

// If property is in both obj1 and obj2 and is different
else if (obj1Val !== obj2Val) {
if(!diff) { diff = {}; }
diff[key] = {
from: obj1Val,
to: obj2Val
Expand Down
2 changes: 1 addition & 1 deletion tests/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const suite = function() {
}

const ops = benchmarker.bench10(suite);
const benchmark = 236941; // update value to set new benchmark
const benchmark = 222587; // update value to set new benchmark
console.info(`Executed ${ops} ops/s`);
const diff = Math.round(100 - ((benchmark / ops) * 100));

Expand Down

0 comments on commit 9b9a754

Please sign in to comment.