Skip to content

Commit 37a394d

Browse files
committed
Remove map and reduce for a single reduce
1 parent 24defbb commit 37a394d

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
@@ -5,15 +5,15 @@ const diff = (lhs, rhs) => {
55

66
if (typeof rhs !== 'object' || rhs === null) return rhs;
77

8-
return Object.keys(rhs).map(key => {
9-
if (!lhs.hasOwnProperty(key)) return { [key]: rhs[key] };
8+
return Object.keys(rhs).reduce((acc, key) => {
9+
if (!lhs.hasOwnProperty(key)) return { ...acc, [key]: rhs[key] };
1010

1111
const lhsValue = lhs[key];
1212
const rhsValue = rhs[key];
13-
if (isEqual(lhsValue, rhsValue)) return {};
13+
if (isEqual(lhsValue, rhsValue)) return acc;
1414

15-
return { [key]: diff(lhsValue, rhsValue) };
16-
}).reduce((acc, next) => ({ ...acc, ...next }), {});
15+
return { ...acc, [key]: diff(lhsValue, rhsValue) };
16+
}, {});
1717
};
1818

1919
export default diff;

0 commit comments

Comments
 (0)