-
-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathadded.js
More file actions
23 lines (15 loc) · 567 Bytes
/
added.js
File metadata and controls
23 lines (15 loc) · 567 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { isEmpty, isObject, hasOwnProperty, makeObjectWithoutPrototype } from './utils.js';
const addedDiff = (lhs, rhs) => {
if (lhs === rhs || !isObject(lhs) || !isObject(rhs)) return {};
return Object.keys(rhs).reduce((acc, key) => {
if (hasOwnProperty(lhs, key)) {
const difference = addedDiff(lhs[key], rhs[key]);
if (isObject(difference) && isEmpty(difference)) return acc;
acc[key] = difference;
return acc;
}
acc[key] = rhs[key];
return acc;
}, makeObjectWithoutPrototype());
};
export default addedDiff;