mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-17 01:59:08 +00:00
remove interactions & worker-utils package, update misc/types
This commit is contained in:
parent
33df1c7edc
commit
503e908e36
25 changed files with 27 additions and 850 deletions
26
packages/misc-utils/collection-tools.ts
Normal file
26
packages/misc-utils/collection-tools.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
export const difference = <T>(...arrays: T[][]) => {
|
||||
return arrays.reduce((a, b) => a.filter((v) => !b.includes(v)));
|
||||
};
|
||||
|
||||
export const groupBy = (arr: Record<string, any>[], key: string) => {
|
||||
return arr.reduce((r, a) => {
|
||||
r[a[key]] = [...r[a[key]], a];
|
||||
return r;
|
||||
}, {});
|
||||
};
|
||||
|
||||
export const keyBy = (arr: Record<string, any>[], key: string) => {
|
||||
return arr.reduce((r, a) => {
|
||||
r[a[key]] = a;
|
||||
return r;
|
||||
}, {});
|
||||
};
|
||||
|
||||
export const union = <T>(...arrays: T[][]) => {
|
||||
return arrays.reduce((a, b) => [...a, ...b]);
|
||||
};
|
||||
|
||||
export const isIdenticalArray = <T>(a1: T[], a2: T[]) => {
|
||||
// DEIs: http://stackoverflow.com/a/40496893/308645
|
||||
return a1.length === a2.length && a1.reduce((a, b) => a && a2.includes(b), true);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue