调整 diff函数

This commit is contained in:
2betop 2020-09-23 11:28:46 +08:00
parent 46ca467911
commit 6cca0a3a70

View File

@ -534,7 +534,8 @@ export function difference<
keepProps?: Array<string>,
strict: boolean = false
): {[propName: string]: any} {
function changes(object: T, base: U, strict: boolean = false) {
function changes(object: T, base: U) {
if (lodashIsObject(object) && lodashIsObject(base)) {
const keys: Array<keyof T & keyof U> = uniq(
Object.keys(object).concat(Object.keys(base))
);
@ -557,7 +558,7 @@ export function difference<
} else if (Array.isArray(a) && Array.isArray(b)) {
if (strict) {
result[key] = a.map((item, index) => {
return changes(item, b[index], strict);
return changes(item, b[index]);
});
let len = b.length - a.length;
@ -567,16 +568,17 @@ export function difference<
} else {
result[key] = a;
}
} else if (lodashIsObject(a) && lodashIsObject(b)) {
result[key] = changes(a as any, b as any);
} else {
result[key] = a;
result[key] = changes(a as any, b as any);
}
});
return result;
} else {
return object;
}
return changes(object, base, strict);
}
return changes(object, base);
}
export const padArr = (arr: Array<any>, size = 4): Array<Array<any>> => {