mergeConcatArray增加了对空数组的容错

This commit is contained in:
Xu Chang 2024-04-30 10:13:35 +08:00
parent 8380982fc4
commit 2d514cd138
3 changed files with 7 additions and 1 deletions

View File

@ -29,5 +29,5 @@ import pullAll from 'lodash/pullAll';
* @returns
*/
declare function mergeConcatArray(object: any, source: any): any;
declare function mergeConcatMany<T>(array: Array<T>): T;
declare function mergeConcatMany<T>(array: Array<T>): T | undefined;
export { unset, pull, uniq, uniqBy, get, set, intersection, intersectionBy, omit, merge, mergeWith, mergeConcatArray, mergeConcatMany, cloneDeep, pick, isEqual, union, difference, differenceBy, groupBy, unionBy, pullAll, };

View File

@ -67,6 +67,9 @@ function mergeConcatArray(object, source) {
}
exports.mergeConcatArray = mergeConcatArray;
function mergeConcatMany(array) {
if (array.length === 0) {
return undefined;
}
return array.reduce((prev, current) => mergeConcatArray(prev, current));
}
exports.mergeConcatMany = mergeConcatMany;

View File

@ -44,6 +44,9 @@ function mergeConcatArray(object: any, source: any) {
}
function mergeConcatMany<T>(array: Array<T>) {
if (array.length === 0) {
return undefined;
}
return array.reduce(
(prev, current) => mergeConcatArray(prev, current)
) as T;