mirror of https://gitee.com/godoos/godoos.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
495 B
22 lines
495 B
export function pick<T, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K> {
|
|
const ret: any = {};
|
|
keys.forEach((key) => {
|
|
ret[key] = obj[key];
|
|
});
|
|
return ret;
|
|
}
|
|
|
|
export function uniq<T>(arr: T[]): T[] {
|
|
return Array.from(new Set(arr));
|
|
}
|
|
export function uniqBy<T>(arr: T[], fn: (item: T) => any): T[] {
|
|
const set = new Set();
|
|
return arr.filter((item) => {
|
|
const val = fn(item);
|
|
if (set.has(val)) {
|
|
return false;
|
|
}
|
|
set.add(val);
|
|
return true;
|
|
});
|
|
}
|
|
|