Merge branch 'main' of https://gitlab.com/phenomLi/StructV2 into main
This commit is contained in:
@@ -47,6 +47,28 @@ export const Util = {
|
||||
return res;
|
||||
},
|
||||
|
||||
/**
|
||||
* 将列表分类
|
||||
* @param list
|
||||
* @param category
|
||||
* @returns
|
||||
*/
|
||||
groupBy<T>(list: T[], category: string): { [key: string]: T[] } {
|
||||
const result = {} as { [key: string]: T[] };
|
||||
|
||||
list.forEach(item => {
|
||||
let value = item[category];
|
||||
|
||||
if(result[value] === undefined) {
|
||||
result[value] = [];
|
||||
}
|
||||
|
||||
result[value].push(item);
|
||||
});
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
/**
|
||||
* 断言函数
|
||||
* @param assertFn
|
||||
|
||||
Reference in New Issue
Block a user