完成仓库模块
This commit is contained in:
10
src/utils/map.ts
Normal file
10
src/utils/map.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* 合并两个对象数组并去重(基于 id,后面的覆盖前面的)
|
||||
*/
|
||||
export function mergeObjectsAndDedupe<T extends { id?: string }>(arr1: T[], arr2: T[]): T[] {
|
||||
const map = new Map(arr1.map((item) => [item.id, item]));
|
||||
arr2.forEach((item) => {
|
||||
if (item.id) map.set(item.id, item);
|
||||
});
|
||||
return [...map.values()];
|
||||
}
|
||||
Reference in New Issue
Block a user