We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 24defbb commit 37a394dCopy full SHA for 37a394d
src/index.js
@@ -5,15 +5,15 @@ const diff = (lhs, rhs) => {
5
6
if (typeof rhs !== 'object' || rhs === null) return rhs;
7
8
- return Object.keys(rhs).map(key => {
9
- if (!lhs.hasOwnProperty(key)) return { [key]: rhs[key] };
+ return Object.keys(rhs).reduce((acc, key) => {
+ if (!lhs.hasOwnProperty(key)) return { ...acc, [key]: rhs[key] };
10
11
const lhsValue = lhs[key];
12
const rhsValue = rhs[key];
13
- if (isEqual(lhsValue, rhsValue)) return {};
+ if (isEqual(lhsValue, rhsValue)) return acc;
14
15
- return { [key]: diff(lhsValue, rhsValue) };
16
- }).reduce((acc, next) => ({ ...acc, ...next }), {});
+ return { ...acc, [key]: diff(lhsValue, rhsValue) };
+ }, {});
17
};
18
19
export default diff;
0 commit comments