Skip to content

Commit bcb3b22

Browse files
committed
Add comments
1 parent 1f25729 commit bcb3b22

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ const isObject = o => o != null && typeof o === 'object';
22
const isEmpty = o => Object.keys(o).length === 0;
33

44
const diff = (lhs, rhs) => {
5-
if (lhs === rhs) return {};
5+
if (lhs === rhs) return {}; // equal return no diff
66

7-
if (!isObject(lhs) || !isObject(rhs)) return rhs;
7+
if (!isObject(lhs) || !isObject(rhs)) return rhs; // return updated rhs
88

99
const deletedValues = Object.keys(lhs).reduce((acc, key) => {
1010
return rhs.hasOwnProperty(key) ? acc : { ...acc, [key]: undefined };
1111
}, {});
1212

1313
return Object.keys(rhs).reduce((acc, key) => {
14-
if (!lhs.hasOwnProperty(key)) return { ...acc, [key]: rhs[key] };
14+
if (!lhs.hasOwnProperty(key)) return { ...acc, [key]: rhs[key] }; // return added rhs key
1515

1616
const difference = diff(lhs[key], rhs[key]);
1717

18-
if (isObject(difference) && isEmpty(difference)) return acc;
18+
if (isObject(difference) && isEmpty(difference)) return acc; // return no diff
1919

20-
return { ...acc, [key]: difference };
20+
return { ...acc, [key]: difference }; // return updated key
2121
}, deletedValues);
2222
};
2323

0 commit comments

Comments
 (0)