Array 数组
uniqueBy
根据属性去重数组
array
目标数组key
属性
类型定义
ts
declare const uniqueBy: <T> (array: T[], key?: string) => T[];
uniqueBy.js
运行代码(Ctrl+S)复制代码
maxNumBy
根据属性找出数组中最大值的一列
array
目标数组key
属性
类型定义
ts
declare const maxNumBy: <T extends Record<any, any>>
(array: T[], key: string) => T | undefined;
maxNumBy.js
运行代码(Ctrl+S)复制代码
minNumBy
根据属性找出数组中最小值的一列
array
目标数组key
属性
类型定义
ts
declare const minNumBy: <T extends Record<any, any>>
(array: T[], key: string) => T | undefined;
minNumBy.js
运行代码(Ctrl+S)复制代码
shuffle
将数组打乱
array
目标数组
类型定义
ts
declare const shuffle: <T>(array: T[]) => T[];
shuffle.js
运行代码(Ctrl+S)复制代码
convertTree
扁平化数组 ==> 树形结构
list
数组Listoption
配置option.pid
父节点id属性名option.id
节点id属性名option.children
节点children属性名option.rootId
根节点id
类型定义
ts
declare const convertTree: <
List extends Record<string, any>,
Child extends string = "children"
>(
list?: List[],
option?: convertTreeOpt
) => Tree<List, Child>[];
convertTree.js
运行代码(Ctrl+S)复制代码
treeFlat
树形结构 ==> 扁平化
nodes
节点树childrenName
节点children属性名
类型定义
ts
declare const treeFlat: <
T extends Record<any, any>,
Child extends string = "children"
>(
nodes: Tree<T, Child>[],
childrenName?: Child
) => T[];
treeFlat.js
运行代码(Ctrl+S)复制代码
convertFlatPaths
树形结构转路径集合
nodes
节点树childrenName
节点children属性名
类型定义
ts
declare const convertFlatPaths: <
T extends Record<any, any>,
Child extends string = "children"
>(
nodes: Tree<T, Child>[],
childrenName?: Child,
path?: T[],
paths?: T[][]
) => T[][];
convertFlatPaths.js
运行代码(Ctrl+S)复制代码
findPathByLeaf
根据 key 递归查找链带关系
leafKey
节点属性名leafValue
节点属性值nodes
节点树childrenName
节点children属性名
类型定义
ts
declare const findPathByLeaf: <
T extends Record<any, any>,
Child extends string = "children"
>(
leafKey: string,
leafValue: any,
nodes: Tree<T, Child>[],
childrenName?: Child,
path?: T[]
) => any;
findPathByLeaf.js
运行代码(Ctrl+S)复制代码
orderBy
返回按属性(sortKey)和顺序(sortBy)排序的对象数组。
array
目标数组sortKey
排序属性sortBy
sortBy 排序方式 'desc降序' 、 'asc升序'
类型定义
ts
declare const orderBy: <
T, sortKey extends keyof T
>(
array: T[],
sortKey: sortKey[],
sortBy: ("asc" | "desc")[]
) => T[];
orderBy.js
运行代码(Ctrl+S)复制代码
whileEach
while 遍历 ArrayList
array
目标数组cb
遍历回调
类型定义
ts
declare function whileEach<T>(
array: T[],
cb: (
curr: T,
index: number,
array: T[]
) => any): void;
whileEach.js
运行代码(Ctrl+S)复制代码